3 * @brief Program to send AP commands to the driver/firmware of the uAP
6 * Copyright (C) 2008-2009, Marvell International Ltd.
8 * This software file (the "File") is distributed by Marvell International
9 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
10 * (the "License"). You may use, redistribute and/or modify this File in
11 * accordance with the terms and conditions of the License, a copy of which
12 * is available along with the File in the gpl.txt file or by writing to
13 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
14 * 02111-1307 or on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
16 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
18 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
19 * this warranty disclaimer.
22 /****************************************************************************
24 03/01/08: Initial creation
25 ****************************************************************************/
27 /****************************************************************************
29 ****************************************************************************/
31 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/select.h>
37 #include <netinet/in.h>
43 #include <sys/ioctl.h>
48 /****************************************************************************
50 ****************************************************************************/
51 /** Default debug level */
52 int debug_level = MSG_NONE;
54 /** Enable or disable debug outputs */
57 /** Convert character to integer */
58 #define CHAR2INT(x) (((x) >= 'A') ? ((x) - 'A' + 10) : ((x) - '0'))
60 /****************************************************************************
62 ****************************************************************************/
64 static char dev_name[IFNAMSIZ + 1];
66 struct option cmd_options[] = {
71 /****************************************************************************
73 ****************************************************************************/
75 * @brief convert char to hex integer
83 if (chr >= '0' && chr <= '9')
85 else if (chr >= 'A' && chr <= 'F')
87 else if (chr >= 'a' && chr <= 'f')
94 * @brief check protocol is valid or not
96 * @param protocol protocol
98 * @return UAP_SUCCESS or UAP_FAILURE
101 is_protocol_valid(int protocol)
103 int ret = UAP_FAILURE;
105 case PROTOCOL_NO_SECURITY:
106 case PROTOCOL_STATIC_WEP:
109 case PROTOCOL_WPA2_MIXED:
113 printf("ERR: Invalid Protocol: %d\n", protocol);
120 * @brief Function to check valid rate
123 * @param rate rate to verify
125 * return UAP_SUCCESS or UAP_FAILURE
128 is_rate_valid(int rate)
130 int ret = UAP_SUCCESS;
153 * @brief detects duplicates rate in array of strings
154 * Note that 0x82 and 0x2 are same for rate
156 * @param argc number of elements
157 * @param argv array of strings
158 * @return UAP_FAILURE or UAP_SUCCESS
161 has_dup_rate(int argc, char *argv[])
164 /* Check for duplicate */
165 for (i = 0; i < (argc - 1); i++) {
166 for (j = i + 1; j < argc; j++) {
167 if ((A2HEXDECIMAL(argv[i]) & ~BASIC_RATE_SET_BIT) ==
168 (A2HEXDECIMAL(argv[j]) & ~BASIC_RATE_SET_BIT)) {
177 * @brief Check for mandatory rates
180 * 2, 4, 11, 22 must be present
182 * 6 12 and 24 must be present for ofdm
184 * @param argc Number of arguments
185 * @param argv Pointer to the arguments
186 * @return UAP_FAILURE or UAP_SUCCESS
190 check_mandatory_rates(int argc, char **argv)
196 #define BITMAP_RATE_1M 0x01
197 #define BITMAP_RATE_2M 0x02
198 #define BITMAP_RATE_5_5M 0x04
199 #define BITMAP_RATE_11M 0x8
200 #define B_RATE_MANDATORY 0x0f
201 #define BITMAP_RATE_6M 0x10
202 #define BITMAP_RATE_12M 0x20
203 #define BITMAP_RATE_24M 0x40
204 #define G_RATE_MANDATORY 0x70
205 for (i = 0; i < argc; i++) {
206 tmp = (A2HEXDECIMAL(argv[i]) & ~BASIC_RATE_SET_BIT);
209 rate_bitmap |= BITMAP_RATE_1M;
212 rate_bitmap |= BITMAP_RATE_2M;
215 rate_bitmap |= BITMAP_RATE_5_5M;
218 rate_bitmap |= BITMAP_RATE_11M;
222 rate_bitmap |= BITMAP_RATE_6M;
226 rate_bitmap |= BITMAP_RATE_12M;
230 rate_bitmap |= BITMAP_RATE_24M;
241 if ((rate_bitmap & B_RATE_MANDATORY) != B_RATE_MANDATORY) {
242 printf("Basic Rates 2, 4, 11 and 22 (500K units) \n"
243 "must be present in basic or non-basic rates\n");
246 if (ofdm_enable && ((rate_bitmap & G_RATE_MANDATORY) != G_RATE_MANDATORY)) {
247 printf("OFDM Rates 12, 24 and 48 ( 500Kb units)\n"
248 "must be present in basic or non-basic rates\n");
255 * @brief detects duplicates channel in array of strings
257 * @param argc number of elements
258 * @param argv array of strings
259 * @return UAP_FAILURE or UAP_SUCCESS
262 has_dup_channel(int argc, char *argv[])
265 /* Check for duplicate */
266 for (i = 0; i < (argc - 1); i++) {
267 for (j = i + 1; j < argc; j++) {
268 if (atoi(argv[i]) == atoi(argv[j])) {
277 * @brief convert string to hex integer
279 * @param s A pointer string buffer
280 * @return hex integer
285 unsigned int val = 0;
286 if (!strncasecmp("0x", s, 2)) {
289 while (*s && isxdigit(*s)) {
290 val = (val << 4) + hexc2bin(*s++);
296 * @brief Dump hex data
298 * @param prompt A pointer prompt buffer
299 * @param p A pointer to data buffer
300 * @param len the len of data buffer
301 * @param delim delim char
305 hexdump_data(char *prompt, void *p, int len, char delim)
308 unsigned char *s = p;
311 printf("%s: len=%d\n", prompt, (int) len);
313 for (i = 0; i < len; i++) {
315 printf("%02x%c", *s++, delim);
317 printf("%02x\n", *s);
318 if ((i + 1) % 16 == 0)
326 * @brief conditional printf
328 * @param level severity level of the message
329 * @param fmt printf format string, followed by optional arguments
332 uap_printf(int level, char *fmt, ...)
336 if (level <= debug_level) {
343 * @brief Dump hex data
345 * @param prompt A pointer prompt buffer
346 * @param p A pointer to data buffer
347 * @param len the len of data buffer
348 * @param delim delim char
352 hexdump(char *prompt, void *p, int len, char delim)
354 if (debug_level < MSG_ALL)
356 hexdump_data(prompt, p, len, delim);
361 * @brief Hex to number
364 * @return Integer value or -1
369 if (c >= '0' && c <= '9')
371 if (c >= 'a' && c <= 'f')
373 if (c >= 'A' && c <= 'F')
380 * @brief Show usage information for the sys_info command
385 print_sys_info_usage(void)
387 printf("\nUsage : sys_info\n");
392 * @brief Parse domain file for country information
394 * @param country Country name
395 * @param sub_bands band information
396 * @return number of band/ UAP_FAILURE
399 parse_domain_file(char *country, IEEEtypes_SubbandSet_t * sub_bands)
403 char domain_name[40];
407 int j = -1, reset_j = 0;
408 u8 no_of_sub_band = 0;
412 fp = fopen("80211d_domain.conf", "r");
414 printf("File opening Error\n");
418 strncpy((char *) country2, country, 2);
423 * Search specific domain name
426 fscanf(fp, "%s", str);
428 strcpy(domain_name, str);
431 if (!strcmp(str, "COUNTRY:")) {
432 /** store next string to domain_name */
436 if (!strcmp(str, country2)) {
437 /** Country is matched ;)*/
438 if (third && !((third == 'I') || (third == 'O') || (third == ' ')))
447 printf("No match found for Country = %s in the 80211d_domain.conf \n",
455 * Search domain specific information
458 fscanf(fp, "%s", str);
460 if (feof(fp) || (dflag && !strcmp(str, "DOMAIN:"))) {
466 if (strchr(str, ','))
469 strcpy(str, strtok(str, ", "));
479 if (IS_HEX_OR_DIGIT(str) == UAP_FAILURE) {
480 printf("ERR: Only Number values are allowed\n");
487 sub_bands[no_of_sub_band].FirstChan = (u8) A2HEXDECIMAL(str);
490 sub_bands[no_of_sub_band].NoOfChan = (u8) A2HEXDECIMAL(str);
493 sub_bands[no_of_sub_band++].MaxTxPwr = (u8) A2HEXDECIMAL(str);
496 printf("ERR: Incorrect 80211d_domain.conf file\n");
507 if (cflag && !strcmp(str, domain_name)) {
508 /* Followed will be the band details */
512 if (!dflag && !strcmp(str, "DOMAIN:")) {
517 return (no_of_sub_band);
523 * @brief Set/Get SNMP MIB
525 * @param action 0-GET 1-SET
527 * @param size size of oid value
528 * @param oid_buf oid value
529 * @return UAP_FAILURE or UAP_SUCCESS
533 sg_snmp_mib(u16 action, u16 oid, u16 size, u8 * oid_buf)
535 APCMDBUF_SNMP_MIB *cmd_buf = NULL;
536 TLVBUF_HEADER *tlv = NULL;
537 int ret = UAP_FAILURE;
543 buf_len = sizeof(APCMDBUF_SNMP_MIB) + sizeof(TLVBUF_HEADER) + size;
544 buf = (u8 *) malloc(buf_len);
546 printf("ERR:Cannot allocate buffer from command!\n");
549 bzero((char *) buf, buf_len);
552 cmd_buf = (APCMDBUF_SNMP_MIB *) buf;
553 tlv = (TLVBUF_HEADER *) (buf + sizeof(APCMDBUF_SNMP_MIB));
554 cmd_buf->Size = buf_len - BUF_HEADER_SIZE;
557 cmd_buf->CmdCode = HostCmd_SNMP_MIB;
559 tlv->Type = uap_cpu_to_le16(oid);
560 tlv->Len = uap_cpu_to_le16(size);
561 for (i = 0; action && (i < size); i++) {
562 tlv->Data[i] = oid_buf[i];
565 cmd_buf->Action = uap_cpu_to_le16(action);
567 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
568 if (ret == UAP_SUCCESS) {
569 if (cmd_buf->Result == CMD_SUCCESS) {
571 /** Reloacte the headers */
573 (TLVBUF_HEADER *) ((u8 *) cmd_buf +
574 sizeof(APCMDBUF_SNMP_MIB));
575 for (i = 0; i < MIN(uap_le16_to_cpu(tlv->Len), size); i++) {
576 oid_buf[i] = tlv->Data[i];
581 printf("ERR:Command Response incorrect!\n");
585 printf("ERR:Command sending failed!\n");
592 * @brief Creates a sys_info request and sends to the driver
596 * @param argc Number of arguments
597 * @param argv Pointer to the arguments
601 apcmd_sys_info(int argc, char *argv[])
603 APCMDBUF_SYS_INFO_REQUEST *cmd_buf = NULL;
604 APCMDBUF_SYS_INFO_RESPONSE *response_buf = NULL;
608 int ret = UAP_FAILURE;
611 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
614 print_sys_info_usage();
621 /* Check arguments */
623 printf("ERR:Too many arguments.\n");
624 print_sys_info_usage();
629 (sizeof(APCMDBUF_SYS_INFO_REQUEST) >=
630 sizeof(APCMDBUF_SYS_INFO_RESPONSE)) ? sizeof(APCMDBUF_SYS_INFO_REQUEST)
631 : sizeof(APCMDBUF_SYS_INFO_RESPONSE);
633 /* alloc buf for command */
634 buf = (u8 *) malloc(buf_len);
637 printf("ERR:Cannot allocate buffer from command!\n");
640 bzero((char *) buf, buf_len);
643 cmd_len = sizeof(APCMDBUF_SYS_INFO_REQUEST);
644 cmd_buf = (APCMDBUF_SYS_INFO_REQUEST *) buf;
645 response_buf = (APCMDBUF_SYS_INFO_RESPONSE *) buf;
647 /* Fill the command buffer */
648 cmd_buf->CmdCode = APCMD_SYS_INFO;
649 cmd_buf->Size = cmd_len;
653 /* Send the command */
654 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
656 /* Process response */
657 if (ret == UAP_SUCCESS) {
658 /* Verify response */
659 if (response_buf->CmdCode != (APCMD_SYS_INFO | APCMD_RESP_CHECK)) {
660 printf("ERR:Corrupted response!\n");
665 if (response_buf->Result == CMD_SUCCESS) {
666 printf("System information = %s\n", response_buf->SysInfo);
668 printf("ERR:Could not retrieve system information!\n");
671 printf("ERR:Command sending failed!\n");
679 * @brief Show usage information for the powermode command
684 print_power_mode_usage(void)
687 ("\nUsage : powermode [MODE] [SLEEP_PARAM=1 CTRL MIN_SLEEP MAX_SLEEP]");
688 printf("\n [INACT_PARAM=2 INACTTO MIN_AWAKE MAX_AWAKE]");
689 printf("\nOptions: MODE : 0 - disable power mode");
690 printf("\n 1 - periodic DTIM power save mode");
691 printf("\n 2 - inactivity based power save mode");
692 printf("\n SLEEP_PARAM:");
694 ("\n CTRL: 0 - disable CTS2Self protection frame Tx before PS");
696 ("\n 1 - enable CTS2Self protection frame Tx before PS");
697 printf("\n MIN_SLEEP: Minimum sleep duration in microseconds");
698 printf("\n MAX_SLEEP: Maximum sleep duration in miroseconds");
699 printf("\n INACT_PARAM: (only for inactivity based power save mode)");
700 printf("\n INACTTO: Inactivity timeout in miroseconds");
701 printf("\n MIN_AWAKE: Minimum awake duration in microseconds");
702 printf("\n MAX_AWAKE: Maximum awake duration in microseconds");
703 printf("\n empty - get current power mode\n");
708 * @brief Set/get power mode
710 * @param pm A pointer to ps_mgmt structure
714 send_power_mode_ioctl(ps_mgmt * pm)
720 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
721 printf("ERR:Cannot open socket\n");
724 /* Initialize the ifr structure */
725 memset(&ifr, 0, sizeof(ifr));
726 strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, strlen(dev_name));
727 ifr.ifr_ifru.ifru_data = (void *) pm;
730 if (ioctl(sockfd, UAP_POWER_MODE, &ifr)) {
732 printf("ERR:UAP_POWER_MODE is not supported by %s\n", dev_name);
735 switch (pm->ps_mode) {
737 printf("power mode = Disabled\n");
740 printf("power mode = Periodic DTIM PS\n");
743 printf("power mode = Inactivity based PS \n");
746 if (pm->flags & PS_FLAG_SLEEP_PARAM) {
747 printf("Sleep param:\n");
748 printf("\tctrl_bitmap=%d\n", (int) pm->sleep_param.ctrl_bitmap);
749 printf("\tmin_sleep=%d us\n", (int) pm->sleep_param.min_sleep);
750 printf("\tmax_sleep=%d us\n", (int) pm->sleep_param.max_sleep);
752 if (pm->flags & PS_FLAG_INACT_SLEEP_PARAM) {
753 printf("Inactivity sleep param:\n");
754 printf("\tinactivity_to=%d us\n", (int) pm->inact_param.inactivity_to);
755 printf("\tmin_awake=%d us\n", (int) pm->inact_param.min_awake);
756 printf("\tmax_awake=%d us\n", (int) pm->inact_param.max_awake);
764 * @brief Creates power mode request and send to driver
765 * and sends to the driver
767 * Usage: "Usage : powermode [MODE]"
769 * Options: MODE : 0 - disable power mode
770 * 1 - enable power mode
771 * 2 - get current power mode
773 * @param argc Number of arguments
774 * @param argv Pointer to the arguments
778 apcmd_power_mode(int argc, char *argv[])
783 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
786 print_power_mode_usage();
793 memset(&pm, 0, sizeof(ps_mgmt));
794 /* Check arguments */
796 ((argc != 0) && (argc != 1) && (argc != 5) && (argc != 9))) {
797 printf("ERR:wrong arguments.\n");
798 print_power_mode_usage();
803 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
804 (atoi(argv[0]) > 2)) {
806 ("ERR:Illegal power mode %s. Must be either '0' '1' or '2'.\n",
808 print_power_mode_usage();
811 pm.flags = PS_FLAG_PS_MODE;
812 pm.ps_mode = atoi(argv[0]);
813 if ((pm.ps_mode == PS_MODE_DISABLE) && (argc > 1)) {
814 printf("ERR: Illegal parameter for disable power mode\n");
815 print_power_mode_usage();
818 if ((pm.ps_mode != PS_MODE_INACTIVITY) && (argc > 5)) {
819 printf("ERR: Illegal parameter\n");
820 print_power_mode_usage();
824 if ((ISDIGIT(argv[1]) == 0) || (atoi(argv[1]) < 1) ||
825 (atoi(argv[1]) > 2)) {
827 ("ERR:Illegal parameter type %s. Must be either '1' or '2'.\n",
829 print_power_mode_usage();
832 type = atoi(argv[1]);
833 if ((type == INACTIVITY_SLEEP_PARAMETER) &&
834 (pm.ps_mode != PS_MODE_INACTIVITY)) {
836 ("ERR: inactivity sleep parameter only valid for inactivity power save mode\n");
837 print_power_mode_usage();
840 if (type == SLEEP_PARAMETER) {
841 if ((ISDIGIT(argv[2]) == 0) || (atoi(argv[2]) < 0) ||
842 (atoi(argv[2]) > 1)) {
844 ("ERR:Illegal ctrl bitmap = %s. Must be either '0' or '1'.\n",
846 print_power_mode_usage();
849 pm.flags |= PS_FLAG_SLEEP_PARAM;
850 pm.sleep_param.ctrl_bitmap = atoi(argv[2]);
851 if ((ISDIGIT(argv[3]) == 0) || (ISDIGIT(argv[4]) == 0)) {
852 printf("ERR:Illegal parameter\n");
853 print_power_mode_usage();
856 pm.sleep_param.min_sleep = atoi(argv[3]);
857 pm.sleep_param.max_sleep = atoi(argv[4]);
858 if (pm.sleep_param.min_sleep > pm.sleep_param.max_sleep) {
860 ("ERR: MIN_SLEEP value should be less than or equal to MAX_SLEEP\n");
863 if (pm.sleep_param.min_sleep < PS_SLEEP_PARAM_MIN ||
864 ((pm.sleep_param.max_sleep > PS_SLEEP_PARAM_MAX) &&
865 pm.sleep_param.ctrl_bitmap)) {
867 ("ERR: Incorrect value of sleep period. Please check README\n");
871 if ((ISDIGIT(argv[2]) == 0) || (ISDIGIT(argv[3]) == 0) ||
872 (ISDIGIT(argv[4]) == 0)) {
873 printf("ERR:Illegal parameter\n");
874 print_power_mode_usage();
877 pm.flags |= PS_FLAG_INACT_SLEEP_PARAM;
878 pm.inact_param.inactivity_to = atoi(argv[2]);
879 pm.inact_param.min_awake = atoi(argv[3]);
880 pm.inact_param.max_awake = atoi(argv[4]);
881 if (pm.inact_param.min_awake > pm.inact_param.max_awake) {
883 ("ERR: MIN_AWAKE value should be less than or equal to MAX_AWAKE\n");
886 if (pm.inact_param.min_awake < PS_AWAKE_PERIOD_MIN) {
887 printf("ERR: Incorrect value of MIN_AWAKE period.\n");
893 if ((ISDIGIT(argv[5]) == 0) || (atoi(argv[5]) < 1) ||
894 (atoi(argv[5]) > 2)) {
896 ("ERR:Illegal parameter type %s. Must be either '1' or '2'.\n",
898 print_power_mode_usage();
901 if (type == atoi(argv[5])) {
902 printf("ERR: Duplicate parameter type %s.\n", argv[5]);
903 print_power_mode_usage();
906 type = atoi(argv[5]);
907 if (type == SLEEP_PARAMETER) {
908 if ((ISDIGIT(argv[6]) == 0) || (atoi(argv[6]) < 0) ||
909 (atoi(argv[6]) > 1)) {
911 ("ERR:Illegal ctrl bitmap = %s. Must be either '0' or '1'.\n",
913 print_power_mode_usage();
916 pm.flags |= PS_FLAG_SLEEP_PARAM;
917 pm.sleep_param.ctrl_bitmap = atoi(argv[6]);
918 if ((ISDIGIT(argv[7]) == 0) || (ISDIGIT(argv[8]) == 0)) {
919 printf("ERR:Illegal parameter\n");
920 print_power_mode_usage();
923 pm.sleep_param.min_sleep = atoi(argv[7]);
924 pm.sleep_param.max_sleep = atoi(argv[8]);
925 if (pm.sleep_param.min_sleep > pm.sleep_param.max_sleep) {
927 ("ERR: MIN_SLEEP value should be less than or equal to MAX_SLEEP\n");
930 if (pm.sleep_param.min_sleep < PS_SLEEP_PARAM_MIN ||
931 ((pm.sleep_param.max_sleep > PS_SLEEP_PARAM_MAX) &&
932 pm.sleep_param.ctrl_bitmap)) {
934 ("ERR: Incorrect value of sleep period. Please check README\n");
938 if ((ISDIGIT(argv[6]) == 0) || (ISDIGIT(argv[7]) == 0) ||
939 (ISDIGIT(argv[8]) == 0)) {
940 printf("ERR:Illegal parameter\n");
941 print_power_mode_usage();
944 pm.flags |= PS_FLAG_INACT_SLEEP_PARAM;
945 pm.inact_param.inactivity_to = atoi(argv[6]);
946 pm.inact_param.min_awake = atoi(argv[7]);
947 pm.inact_param.max_awake = atoi(argv[8]);
948 if (pm.inact_param.min_awake > pm.inact_param.max_awake) {
950 ("ERR: MIN_AWAKE value should be less than or equal to MAX_AWAKE\n");
953 if (pm.inact_param.min_awake < PS_AWAKE_PERIOD_MIN) {
954 printf("ERR: Incorrect value of MIN_AWAKE period.\n");
960 send_power_mode_ioctl(&pm);
965 * @brief Show usage information for the sys_reset command
970 print_sys_reset_usage(void)
972 printf("\nUsage : sys_reset\n");
977 * @brief Creates a sys_reset request and sends to the driver
981 * @param argc Number of arguments
982 * @param argv Pointer to the arguments
986 apcmd_sys_reset(int argc, char *argv[])
988 APCMDBUF_SYS_RESET *cmd_buf = NULL;
991 int ret = UAP_FAILURE;
995 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
998 print_sys_reset_usage();
1005 /* Check arguments */
1007 printf("ERR:Too many arguments.\n");
1008 print_sys_reset_usage();
1012 memset(&pm, 0, sizeof(ps_mgmt));
1013 pm.flags = PS_FLAG_PS_MODE;
1014 pm.ps_mode = PS_MODE_DISABLE;
1015 send_power_mode_ioctl(&pm);
1017 /* Initialize the command length */
1018 cmd_len = sizeof(APCMDBUF_SYS_RESET);
1020 /* Initialize the command buffer */
1021 buffer = (u8 *) malloc(cmd_len);
1024 printf("ERR:Cannot allocate buffer for command!\n");
1027 bzero((char *) buffer, cmd_len);
1029 /* Locate headers */
1030 cmd_buf = (APCMDBUF_SYS_RESET *) buffer;
1032 /* Fill the command buffer */
1033 cmd_buf->CmdCode = APCMD_SYS_RESET;
1034 cmd_buf->Size = cmd_len;
1035 cmd_buf->SeqNum = 0;
1036 cmd_buf->Result = 0;
1038 /* Send the command */
1039 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
1041 /* Process response */
1042 if (ret == UAP_SUCCESS) {
1043 /* Verify response */
1044 if (cmd_buf->CmdCode != (APCMD_SYS_RESET | APCMD_RESP_CHECK)) {
1045 printf("ERR:Corrupted response!\n");
1049 /* Print response */
1050 if (cmd_buf->Result == CMD_SUCCESS) {
1051 printf("System reset successful!\n");
1053 printf("ERR:Could not reset system!\n");
1056 printf("ERR:Command sending failed!\n");
1064 * @brief Show usage information for the bss_start command
1069 print_bss_start_usage(void)
1071 printf("\nUsage : bss_start\n");
1076 * @brief Creates a BSS start request and sends to the driver
1078 * Usage: "bss_start"
1080 * @param argc Number of arguments
1081 * @param argv Pointer to the arguments
1085 apcmd_bss_start(int argc, char *argv[])
1087 APCMDBUF_BSS_START *cmd_buf = NULL;
1090 int ret = UAP_FAILURE;
1093 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
1096 print_bss_start_usage();
1103 /* Check arguments */
1105 printf("ERR:Too many arguments.\n");
1106 print_bss_start_usage();
1110 /* Initialize the command length */
1111 cmd_len = sizeof(APCMDBUF_BSS_START);
1113 /* Initialize the command buffer */
1114 buffer = (u8 *) malloc(cmd_len);
1117 printf("ERR:Cannot allocate buffer for command!\n");
1120 bzero((char *) buffer, cmd_len);
1122 /* Locate headers */
1123 cmd_buf = (APCMDBUF_BSS_START *) buffer;
1125 /* Fill the command buffer */
1126 cmd_buf->CmdCode = APCMD_BSS_START;
1127 cmd_buf->Size = cmd_len;
1128 cmd_buf->SeqNum = 0;
1129 cmd_buf->Result = 0;
1131 /* Send the command */
1132 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
1134 /* Process response */
1135 if (ret == UAP_SUCCESS) {
1136 /* Verify response */
1137 if (cmd_buf->CmdCode != (APCMD_BSS_START | APCMD_RESP_CHECK)) {
1138 printf("ERR:Corrupted response!\n");
1143 /* Print response */
1144 if (cmd_buf->Result == CMD_SUCCESS) {
1145 printf("BSS started!\n");
1146 } else if (cmd_buf->Result == BSS_FAILURE_START_INVAL) {
1147 printf("ERR:Could not start BSS! Invalid BSS parameters.\n");
1148 } else if (cmd_buf->Result == BSS_FAILURE_START_REDUNDANT) {
1149 printf("ERR:Could not start BSS! BSS already started.\n");
1151 printf("ERR:Could not start BSS!\n");
1154 printf("ERR:Command sending failed!\n");
1162 * @brief Show usage information for the bss_stop command
1167 print_bss_stop_usage(void)
1169 printf("\nUsage : bss_stop\n");
1174 * @brief Creates a BSS stop request and sends to the driver
1178 * @param argc Number of arguments
1179 * @param argv Pointer to the arguments
1183 apcmd_bss_stop(int argc, char *argv[])
1185 APCMDBUF_BSS_STOP *cmd_buf = NULL;
1188 int ret = UAP_FAILURE;
1191 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
1194 print_bss_stop_usage();
1199 argv += optind; /* Check arguments */
1202 printf("ERR:Too many arguments.\n");
1203 print_bss_stop_usage();
1206 /* Initialize the command length */
1207 cmd_len = sizeof(APCMDBUF_BSS_STOP);
1209 /* Initialize the command buffer */
1210 buffer = (u8 *) malloc(cmd_len);
1213 printf("ERR:Cannot allocate buffer for command!\n");
1216 bzero((char *) buffer, cmd_len);
1218 /* Locate headers */
1219 cmd_buf = (APCMDBUF_BSS_STOP *) buffer;
1221 /* Fill the command buffer */
1222 cmd_buf->CmdCode = APCMD_BSS_STOP;
1223 cmd_buf->Size = cmd_len;
1224 cmd_buf->SeqNum = 0;
1225 cmd_buf->Result = 0;
1227 /* Send the command */
1228 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
1230 /* Process response */
1231 if (ret == UAP_SUCCESS) {
1232 /* Verify response */
1233 if (cmd_buf->CmdCode != (APCMD_BSS_STOP | APCMD_RESP_CHECK)) {
1234 printf("ERR:Corrupted response!\n");
1239 /* Print response */
1240 if (cmd_buf->Result == CMD_SUCCESS) {
1241 printf("BSS stopped!\n");
1242 } else if (cmd_buf->Result == BSS_FAILURE_STOP_REDUNDANT) {
1243 printf("ERR:Could not stop BSS! BSS already stopped.\n");
1244 } else if (cmd_buf->Result == BSS_FAILURE_STOP_INVAL) {
1245 printf("ERR:Could not stop BSS! No active BSS.\n");
1247 printf("ERR:Could not stop BSS!\n");
1250 printf("ERR:Command sending failed!\n");
1258 * @brief Show usage information for the sta_list command
1263 print_sta_list_usage(void)
1265 printf("\nUsage : sta_list\n");
1270 * @brief Creates a STA list request and sends to the driver
1274 * @param argc Number of arguments
1275 * @param argv Pointer to the arguments
1279 apcmd_sta_list(int argc, char *argv[])
1281 APCMDBUF_STA_LIST_REQUEST *cmd_buf = NULL;
1282 APCMDBUF_STA_LIST_RESPONSE *response_buf = NULL;
1285 TLVBUF_STA_INFO *tlv = NULL;
1288 int ret = UAP_FAILURE;
1293 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
1296 print_sta_list_usage();
1303 /* Check arguments */
1305 printf("ERR:Too many arguments.\n");
1306 print_sta_list_usage();
1310 sizeof(APCMDBUF_STA_LIST_RESPONSE) +
1311 (MAX_NUM_CLIENTS * sizeof(TLVBUF_STA_INFO));
1312 if (response_len > sizeof(APCMDBUF_STA_LIST_REQUEST))
1313 buf_len = response_len;
1315 buf_len = sizeof(APCMDBUF_STA_LIST_REQUEST);
1317 /* Initialize the command length */
1318 cmd_len = sizeof(APCMDBUF_STA_LIST_REQUEST);
1320 /* Initialize the command buffer */
1321 buf = (u8 *) malloc(buf_len);
1324 printf("ERR:Cannot allocate buffer from command!\n");
1327 bzero((char *) buf, buf_len);
1329 /* Locate headers */
1330 cmd_buf = (APCMDBUF_STA_LIST_REQUEST *) buf;
1331 response_buf = (APCMDBUF_STA_LIST_RESPONSE *) buf;
1333 /* Fill the command buffer */
1334 cmd_buf->CmdCode = APCMD_STA_LIST;
1335 cmd_buf->Size = cmd_len;
1336 cmd_buf->SeqNum = 0;
1337 cmd_buf->Result = 0;
1339 /* Send the command */
1340 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
1341 response_buf->StaCount = uap_le16_to_cpu(response_buf->StaCount);
1343 /* Process response */
1344 if (ret == UAP_SUCCESS) {
1345 /* Verify response */
1346 if (response_buf->CmdCode != (APCMD_STA_LIST | APCMD_RESP_CHECK)) {
1347 printf("ERR:Corrupted response!\n");
1352 /* Print response */
1353 if (response_buf->Result == CMD_SUCCESS) {
1354 printf("Number of STA = %d\n\n", response_buf->StaCount);
1355 for (i = 0; i < response_buf->StaCount; i++) {
1356 tlv = (TLVBUF_STA_INFO *) (&response_buf->StaList[i]);
1357 endian_convert_tlv_header_in(tlv);
1359 if (tlv->Tag != MRVL_STA_INFO_TLV_ID) {
1360 printf("STA %d information corrupted.\n", i + 1);
1363 printf("STA %d information:\n", i + 1);
1364 printf("=====================\n");
1365 printf("MAC Address: ");
1366 print_mac(tlv->MacAddress);
1367 printf("\nPower mfg status: %s\n",
1368 (tlv->PowerMfgStatus ==
1369 0) ? "active" : "power save");
1370 /** On some platform, s8 is same as unsigned char*/
1371 rssi = (int) tlv->Rssi;
1373 rssi = -(256 - rssi);
1374 printf("Rssi : %d dBm\n\n", rssi);
1376 printf("ERR:Unable to find information for STA %d\n\n",
1381 printf("ERR:Could not get STA list!\n");
1384 printf("ERR:Command sending failed!\n");
1391 * @brief Show usage information for the sta_deauth command
1396 print_sta_deauth_usage(void)
1398 printf("\nUsage : sta_deauth <STA_MAC_ADDRESS> [REASON_CODE]\n");
1403 * @brief Creates a STA deauth request and sends to the driver
1405 * Usage: "sta_deauth <STA_MAC_ADDRESS>"
1407 * @param argc Number of arguments
1408 * @param argv Pointer to the arguments
1412 apcmd_sta_deauth(int argc, char *argv[])
1414 APCMDBUF_STA_DEAUTH *cmd_buf = NULL;
1417 int ret = UAP_FAILURE;
1420 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
1423 print_sta_deauth_usage();
1430 /* Check arguments */
1431 if (argc != 1 && argc != 2) {
1432 printf("ERR:wrong arguments! Must provide STA_MAC_ADDRESS.\n");
1433 printf("\t\t with optional REASON_CODE.\n");
1434 print_sta_deauth_usage();
1438 /* Check Reason Code */
1440 if (IS_HEX_OR_DIGIT(argv[1]) == UAP_FAILURE) {
1441 printf("ERR: Invalid input for reason code\n");
1442 print_sta_deauth_usage();
1447 /* Initialize the command length */
1448 cmd_len = sizeof(APCMDBUF_STA_DEAUTH);
1450 /* Initialize the command buffer */
1451 buffer = (u8 *) malloc(cmd_len);
1453 printf("ERR:Cannot allocate buffer for command!\n");
1456 bzero((char *) buffer, cmd_len);
1458 /* Locate headers */
1459 cmd_buf = (APCMDBUF_STA_DEAUTH *) buffer;
1461 /* Fill the command buffer */
1462 cmd_buf->CmdCode = APCMD_STA_DEAUTH;
1463 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
1464 cmd_buf->SeqNum = 0;
1465 cmd_buf->Result = 0;
1466 if ((ret = mac2raw(argv[0], cmd_buf->StaMacAddress)) != UAP_SUCCESS) {
1467 printf("ERR: %s Address\n", ret == UAP_FAILURE ? "Invalid MAC" :
1468 ret == UAP_RET_MAC_BROADCAST ? "Broadcast" : "Multicast");
1473 cmd_buf->ReasonCode = uap_cpu_to_le16((u16) A2HEXDECIMAL(argv[1]));
1476 /* Send the command */
1477 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
1479 /* Process response */
1480 if (ret == UAP_SUCCESS) {
1481 /* Verify response */
1482 if (cmd_buf->CmdCode != (APCMD_STA_DEAUTH | APCMD_RESP_CHECK)) {
1483 printf("ERR:Corrupted response!\n");
1488 /* Print response */
1489 if (cmd_buf->Result == CMD_SUCCESS) {
1490 printf("Deauthentication successful!\n");
1492 printf("ERR:Deauthentication unsuccessful!\n");
1495 printf("ERR:Command sending failed!\n");
1503 * @brief Show usage information for the coex_config command
1508 print_coex_config_usage(void)
1510 printf("\nUsage : coex_config [CONFIG_FILE]\n");
1512 ("\nIf CONFIG_FILE is provided, a 'set' is performed, else a 'get' is performed.\n");
1517 * @brief Creates a coex_config request and sends to the driver
1519 * Usage: "Usage : coex_config [CONFIG_FILE]"
1521 * @param argc Number of arguments
1522 * @param argv Pointer to the arguments
1523 * @return UAP_SUCCESS or UAP_FAILURE
1526 apcmd_coex_config(int argc, char *argv[])
1528 apcmdbuf_coex_config *cmd_buf = NULL;
1529 tlvbuf_coex_common_cfg *coex_common_tlv;
1530 tlvbuf_coex_sco_cfg *coex_sco_tlv;
1531 tlvbuf_coex_acl_cfg *coex_acl_tlv;
1532 tlvbuf_coex_stats *coex_stats_tlv;
1535 int ret = UAP_FAILURE;
1538 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
1541 print_coex_config_usage();
1548 /* Check arguments */
1550 printf("ERR:Too many arguments.\n");
1551 print_coex_config_usage();
1555 /* Read profile and send command to firmware */
1556 apcmd_coex_config_profile(argc, argv);
1560 /* fixed command length */
1561 cmd_len = sizeof(apcmdbuf_coex_config) + sizeof(tlvbuf_coex_common_cfg)
1562 + sizeof(tlvbuf_coex_sco_cfg) + sizeof(tlvbuf_coex_acl_cfg)
1563 + sizeof(tlvbuf_coex_stats);
1564 /* alloc buf for command */
1565 buf = (u8 *) malloc(cmd_len);
1567 printf("ERR:Cannot allocate buffer from command!\n");
1570 bzero((char *) buf, cmd_len);
1572 cmd_buf = (apcmdbuf_coex_config *) buf;
1574 coex_common_tlv = (tlvbuf_coex_common_cfg *) cmd_buf->tlv_buffer;
1575 coex_common_tlv->Tag = MRVL_BT_COEX_COMMON_CFG_TLV_ID;
1576 coex_common_tlv->Length =
1577 sizeof(tlvbuf_coex_common_cfg) - sizeof(TLVBUF_HEADER);
1578 endian_convert_tlv_header_out(coex_common_tlv);
1580 coex_sco_tlv = (tlvbuf_coex_sco_cfg *) (cmd_buf->tlv_buffer +
1581 sizeof(tlvbuf_coex_common_cfg));
1582 coex_sco_tlv->Tag = MRVL_BT_COEX_SCO_CFG_TLV_ID;
1583 coex_sco_tlv->Length = sizeof(tlvbuf_coex_sco_cfg) - sizeof(TLVBUF_HEADER);
1584 endian_convert_tlv_header_out(coex_sco_tlv);
1586 coex_acl_tlv = (tlvbuf_coex_acl_cfg *) (cmd_buf->tlv_buffer +
1587 sizeof(tlvbuf_coex_common_cfg) +
1588 sizeof(tlvbuf_coex_sco_cfg));
1589 coex_acl_tlv->Tag = MRVL_BT_COEX_ACL_CFG_TLV_ID;
1590 coex_acl_tlv->Length = sizeof(tlvbuf_coex_acl_cfg) - sizeof(TLVBUF_HEADER);
1591 endian_convert_tlv_header_out(coex_acl_tlv);
1593 coex_stats_tlv = (tlvbuf_coex_stats *) (cmd_buf->tlv_buffer +
1594 sizeof(tlvbuf_coex_common_cfg) +
1595 sizeof(tlvbuf_coex_sco_cfg)
1596 + sizeof(tlvbuf_coex_acl_cfg));
1597 coex_stats_tlv->Tag = MRVL_BT_COEX_STATS_TLV_ID;
1598 coex_stats_tlv->Length = sizeof(tlvbuf_coex_stats) - sizeof(TLVBUF_HEADER);
1599 endian_convert_tlv_header_out(coex_stats_tlv);
1601 /* Fill the command buffer */
1602 cmd_buf->CmdCode = HostCmd_ROBUST_COEX;
1603 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
1604 cmd_buf->SeqNum = 0;
1605 cmd_buf->Result = 0;
1606 cmd_buf->action = uap_cpu_to_le16(ACTION_GET);
1608 /* Send the command */
1609 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
1611 /* Process response */
1612 if (ret == UAP_SUCCESS) {
1613 /* Verify response */
1614 if (cmd_buf->CmdCode != (HostCmd_ROBUST_COEX | APCMD_RESP_CHECK)) {
1615 printf("ERR:Corrupted response!\n");
1619 /* Print response */
1620 if (cmd_buf->Result == CMD_SUCCESS) {
1621 printf("BT Coex settings:\n");
1622 print_tlv(buf + sizeof(apcmdbuf_coex_config),
1623 cmd_buf->Size - sizeof(apcmdbuf_coex_config) +
1626 printf("ERR:Could not retrieve coex configuration.\n");
1629 printf("ERR:Command sending failed!\n");
1636 * @brief Show usage information for the sys_config command
1641 print_sys_config_usage(void)
1643 printf("\nUsage : sys_config [CONFIG_FILE]\n");
1645 ("\nIf CONFIG_FILE is provided, a 'set' is performed, else a 'get' is performed.\n");
1646 printf("CONFIG_FILE is file contain all the Micro AP settings.\n");
1651 * @brief Show usage information for the rdeeprom command
1656 print_apcmd_read_eeprom_usage(void)
1658 printf("\nUsage: rdeeprom <offset> <bytecount>\n");
1659 printf(" offset : 0,4,8,..., multiple of 4\n");
1660 printf(" bytecount : 4-20, multiple of 4\n");
1665 * @brief Show protocol tlv
1667 * @param tlv Poniter to protocol tlv
1672 print_protocol(TLVBUF_PROTOCOL * tlv)
1674 switch (tlv->Protocol) {
1676 case PROTOCOL_NO_SECURITY:
1677 printf("PROTOCOL = No security\n");
1679 case PROTOCOL_STATIC_WEP:
1680 printf("PROTOCOL = Static WEP\n");
1683 printf("PROTOCOL = WPA \n");
1686 printf("PROTOCOL = WPA2 \n");
1688 case PROTOCOL_WPA | PROTOCOL_WPA2:
1689 printf("PROTOCOL = WPA/WPA2 \n");
1692 printf("Unknown PROTOCOL: 0x%x \n", tlv->Protocol);
1698 * @brief Show wep tlv
1700 * @param tlv Poniter to wep tlv
1705 print_wep_key(TLVBUF_WEP_KEY * tlv)
1708 if (tlv->Length <= 2) {
1709 printf("wrong wep_key tlv: length=%d\n", tlv->Length);
1712 printf("WEP KEY_%d = ", tlv->KeyIndex);
1713 for (i = 0; i < tlv->Length - 2; i++)
1714 printf("%02x ", tlv->Key[i]);
1716 printf("\nDefault WEP Key = %d\n", tlv->KeyIndex);
1722 * @brief Parses a command line
1724 * @param line The line to parse
1725 * @param args Pointer to the argument buffer to be filled in
1726 * @return Number of arguments in the line or EOF
1729 parse_line(char *line, char *args[])
1738 length = strlen(line);
1741 /* Find number of arguments */
1744 for (i = 0; i < length; i++) {
1745 /* Ignore leading spaces */
1746 if (is_start == 0) {
1747 if (line[i] == ' ') {
1749 } else if (line[i] == '\t') {
1751 } else if (line[i] == '\n') {
1755 args[arg_num] = &line[i];
1759 if (is_start == 1) {
1760 /* Ignore comments */
1761 if (line[i] == '#') {
1766 /* Separate by '=' */
1767 if (line[i] == '=') {
1772 /* Separate by ',' */
1773 if (line[i] == ',') {
1778 /* Change ',' to ' ', but not inside quotes */
1779 if ((line[i] == ',') && (is_quote == 0)) {
1784 /* Remove newlines */
1785 if (line[i] == '\n') {
1788 /* Check for quotes */
1789 if (line[i] == '"') {
1790 is_quote = (is_quote == 1) ? 0 : 1;
1793 if (((line[i] == ' ') || (line[i] == '\t')) && (is_quote == 0)) {
1803 * @brief Parse function for a configuration line
1805 * @param s Storage buffer for data
1806 * @param size Maximum size of data
1807 * @param stream File stream pointer
1808 * @param line Pointer to current line within the file
1809 * @param _pos Output string or NULL
1810 * @return String or NULL
1813 config_get_line(char *s, int size, FILE * stream, int *line, char **_pos)
1815 char *pos, *end, *sstart;
1816 while (fgets(s, size, stream)) {
1820 /* Skip white space from the beginning of line. */
1821 while (*pos == ' ' || *pos == '\t' || *pos == '\r')
1823 /* Skip comment lines and empty lines */
1824 if (*pos == '#' || *pos == '\n' || *pos == '\0')
1827 * Remove # comments unless they are within a double quoted
1830 sstart = strchr(pos, '"');
1832 sstart = strrchr(sstart + 1, '"');
1835 end = strchr(sstart, '#');
1839 end = pos + strlen(pos) - 1;
1840 /* Remove trailing white space. */
1842 (*end == '\n' || *end == ' ' || *end == '\t' || *end == '\r'))
1857 * @brief Read the profile and sends to the driver
1859 * @param argc Number of arguments
1860 * @param argv Pointer to the arguments
1861 * @return UAP_SUCCESS or UAP_FAILURE
1864 apcmd_coex_config_profile(int argc, char *argv[])
1866 FILE *config_file = NULL;
1868 int i, ret, index, li = 0;
1872 int is_coex_config = 0;
1873 int is_coex_common_config = 0;
1874 int is_coex_sco_config = 0;
1875 int is_coex_acl_config = 0;
1877 apcmdbuf_coex_config *cmd_buf = NULL;
1878 tlvbuf_coex_common_cfg *coex_common_tlv;
1879 tlvbuf_coex_sco_cfg *coex_sco_tlv;
1880 tlvbuf_coex_acl_cfg *coex_acl_tlv;
1881 u16 acl_enabled = 0;
1882 u32 conf_bitmap = 0;
1883 u16 cmd_len = 0, tlv_len = 0;
1884 u16 sco_prot_qtime[4] = { 0, 0, 0, 0 }, sco_prot_rate = 0, sco_acl_freq = 0;
1885 u16 acl_bt_time = 0, acl_wlan_time = 0, acl_prot_rate = 0;
1887 /* Check if file exists */
1888 config_file = fopen(argv[0], "r");
1889 if (config_file == NULL) {
1890 printf("\nERR:Config file can not open.\n");
1893 line = (char *) malloc(MAX_CONFIG_LINE);
1895 printf("ERR:Cannot allocate memory for line\n");
1898 bzero(line, MAX_CONFIG_LINE);
1900 /* fixed command length */
1901 cmd_len = sizeof(apcmdbuf_coex_config) + sizeof(tlvbuf_coex_common_cfg)
1902 + sizeof(tlvbuf_coex_sco_cfg) + sizeof(tlvbuf_coex_acl_cfg);
1903 /* alloc buf for command */
1904 buf = (u8 *) malloc(cmd_len);
1906 printf("ERR:Cannot allocate buffer from command!\n");
1909 bzero((char *) buf, cmd_len);
1911 cmd_buf = (apcmdbuf_coex_config *) buf;
1913 /* Fill the command buffer */
1914 cmd_buf->CmdCode = HostCmd_ROBUST_COEX;
1915 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
1916 cmd_buf->SeqNum = 0;
1917 cmd_buf->Result = 0;
1918 cmd_buf->action = uap_cpu_to_le16(ACTION_SET);
1920 /* Parse file and process */
1921 while (config_get_line(line, MAX_CONFIG_LINE, config_file, &li, &pos)) {
1923 uap_printf(MSG_DEBUG, "DBG:Received config line (%d) = %s\n", li, line);
1925 arg_num = parse_line(line, args);
1927 uap_printf(MSG_DEBUG, "DBG:Number of arguments = %d\n", arg_num);
1928 for (i = 0; i < arg_num; i++) {
1929 uap_printf(MSG_DEBUG, "\tDBG:Argument %d. %s\n", i + 1, args[i]);
1932 /* Check for end of Coex configurations */
1933 if (is_coex_acl_config == 1) {
1934 if (strcmp(args[0], "}") == 0) {
1936 (tlvbuf_coex_acl_cfg *) (cmd_buf->tlv_buffer + tlv_len);
1937 coex_acl_tlv->Tag = MRVL_BT_COEX_ACL_CFG_TLV_ID;
1938 coex_acl_tlv->Length =
1939 sizeof(tlvbuf_coex_acl_cfg) - sizeof(TLVBUF_HEADER);
1940 endian_convert_tlv_header_out(coex_acl_tlv);
1941 coex_acl_tlv->enabled = uap_cpu_to_le16(acl_enabled);
1942 coex_acl_tlv->bt_time = uap_cpu_to_le16(acl_bt_time);
1943 coex_acl_tlv->wlan_time = uap_cpu_to_le16(acl_wlan_time);
1944 coex_acl_tlv->protection_rate = uap_cpu_to_le16(acl_prot_rate);
1945 tlv_len += sizeof(tlvbuf_coex_acl_cfg);
1946 is_coex_acl_config = 0;
1948 } else if (is_coex_sco_config == 1) {
1949 if (strcmp(args[0], "}") == 0) {
1951 (tlvbuf_coex_sco_cfg *) (cmd_buf->tlv_buffer + tlv_len);
1952 coex_sco_tlv->Tag = MRVL_BT_COEX_SCO_CFG_TLV_ID;
1953 coex_sco_tlv->Length =
1954 sizeof(tlvbuf_coex_sco_cfg) - sizeof(TLVBUF_HEADER);
1955 endian_convert_tlv_header_out(coex_sco_tlv);
1956 for (i = 0; i < 4; i++)
1957 coex_sco_tlv->protection_qtime[i] =
1958 uap_cpu_to_le16(sco_prot_qtime[i]);
1959 coex_sco_tlv->protection_rate = uap_cpu_to_le16(sco_prot_rate);
1960 coex_sco_tlv->acl_frequency = uap_cpu_to_le16(sco_acl_freq);
1961 tlv_len += sizeof(tlvbuf_coex_sco_cfg);
1962 is_coex_sco_config = 0;
1964 } else if (is_coex_common_config == 1) {
1965 if (strcmp(args[0], "}") == 0) {
1967 (tlvbuf_coex_common_cfg *) (cmd_buf->tlv_buffer + tlv_len);
1968 coex_common_tlv->Tag = MRVL_BT_COEX_COMMON_CFG_TLV_ID;
1969 coex_common_tlv->Length =
1970 sizeof(tlvbuf_coex_common_cfg) - sizeof(TLVBUF_HEADER);
1971 endian_convert_tlv_header_out(coex_common_tlv);
1972 coex_common_tlv->config_bitmap = uap_cpu_to_le32(conf_bitmap);
1973 tlv_len += sizeof(tlvbuf_coex_common_cfg);
1974 is_coex_common_config = 0;
1976 } else if (is_coex_config == 1) {
1977 if (strcmp(args[0], "}") == 0)
1980 if (strcmp(args[0], "coex_config") == 0) {
1982 } else if (strcmp(args[0], "common_config") == 0) {
1983 is_coex_common_config = 1;
1984 } else if (strcmp(args[0], "sco_config") == 0) {
1985 is_coex_sco_config = 1;
1986 } else if (strcmp(args[0], "acl_config") == 0) {
1987 is_coex_acl_config = 1;
1989 if ((strcmp(args[0], "bitmap") == 0) && is_coex_common_config) {
1990 if (is_input_valid(COEX_COMM_BITMAP, arg_num - 1, args + 1) !=
1994 conf_bitmap = (u32) A2HEXDECIMAL(args[1]);
1995 } else if ((strncmp(args[0], "protectionFromQTime", 19) == 0) &&
1996 is_coex_sco_config) {
1997 index = atoi(args[0] + strlen("protectionFromQTime"));
1998 if (index < 0 || index > 3) {
1999 printf("ERR:Incorrect index %d.\n", index);
2002 if (is_input_valid(COEX_PROTECTION, arg_num, args) != UAP_SUCCESS) {
2005 sco_prot_qtime[index] = (u16) atoi(args[1]);
2006 } else if ((strcmp(args[0], "scoProtectionFromRate") == 0) &&
2007 is_coex_sco_config) {
2008 if (is_input_valid(COEX_PROTECTION, arg_num, args) != UAP_SUCCESS) {
2011 sco_prot_rate = (u16) atoi(args[1]);
2012 } else if ((strcmp(args[0], "aclFrequency") == 0) && is_coex_sco_config) {
2013 if (is_input_valid(COEX_SCO_ACL_FREQ, arg_num - 1, args + 1) !=
2017 sco_acl_freq = (u16) atoi(args[1]);
2018 } else if ((strcmp(args[0], "enabled") == 0) && is_coex_acl_config) {
2019 if (is_input_valid(COEX_ACL_ENABLED, arg_num - 1, args + 1) !=
2023 acl_enabled = (u16) atoi(args[1]);
2024 } else if ((strcmp(args[0], "btTime") == 0) && is_coex_acl_config) {
2025 if (is_input_valid(COEX_ACL_BT_TIME, arg_num - 1, args + 1) !=
2029 acl_bt_time = (u16) atoi(args[1]);
2030 } else if ((strcmp(args[0], "wlanTime") == 0) && is_coex_acl_config) {
2031 if (is_input_valid(COEX_ACL_WLAN_TIME, arg_num - 1, args + 1) !=
2035 acl_wlan_time = (u16) atoi(args[1]);
2036 } else if ((strcmp(args[0], "aclProtectionFromRate") == 0) &&
2037 is_coex_acl_config) {
2038 if (is_input_valid(COEX_PROTECTION, arg_num, args) != UAP_SUCCESS) {
2041 acl_prot_rate = (u16) atoi(args[1]);
2044 /* Send the command */
2045 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
2047 /* Process response */
2048 if (ret == UAP_SUCCESS) {
2049 /* Verify response */
2050 if (cmd_buf->CmdCode != (HostCmd_ROBUST_COEX | APCMD_RESP_CHECK)) {
2051 printf("ERR:Corrupted response!\n");
2054 /* Print response */
2055 if (cmd_buf->Result == CMD_SUCCESS) {
2056 printf("BT Coex settings sucessfully set.\n");
2058 printf("ERR:Could not set coex configuration.\n");
2061 printf("ERR:Command sending failed!\n");
2064 fclose(config_file);
2072 * @brief Read the profile and sends to the driver
2074 * @param argc Number of arguments
2075 * @param argv Pointer to the arguments
2076 * @return UAP_SUCCESS or UAP_FAILURE
2079 apcmd_sys_config_profile(int argc, char *argv[])
2081 FILE *config_file = NULL;
2088 int is_ap_config = 0;
2089 int is_custom_ie_config = 0;
2090 int is_ap_mac_filter = 0;
2091 APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
2097 u16 mask_ie_index = 0;
2099 int pairwisecipher = -1;
2100 int groupcipher = -1;
2101 TLVBUF_STA_MAC_ADDR_FILTER *filter_tlv = NULL;
2102 tlvbuf_custom_ie *custom_ie_tlv_head = NULL;
2103 tlvbuf_custom_ie *custom_ie_tlv = NULL;
2104 custom_ie *custom_ie_ptr = NULL;
2105 int custom_ie_tlv_len = 0;
2106 int custom_mask_count = 0;
2107 int custom_buf_count = 0;
2108 int filter_mac_count = -1;
2109 int tx_data_rate = -1;
2110 int mcbc_data_rate = -1;
2113 char country_80211d[4];
2115 int flag_80211d = 0;
2117 memset(rate, 0, MAX_RATES);
2118 /* Check if file exists */
2119 config_file = fopen(argv[0], "r");
2120 if (config_file == NULL) {
2121 printf("\nERR:Config file can not open.\n");
2124 line = (char *) malloc(MAX_CONFIG_LINE);
2126 printf("ERR:Cannot allocate memory for line\n");
2129 bzero(line, MAX_CONFIG_LINE);
2131 /* Parse file and process */
2132 while (config_get_line(line, MAX_CONFIG_LINE, config_file, &li, &pos)) {
2134 uap_printf(MSG_DEBUG, "DBG:Received config line (%d) = %s\n", li, line);
2136 arg_num = parse_line(line, args);
2138 uap_printf(MSG_DEBUG, "DBG:Number of arguments = %d\n", arg_num);
2139 for (i = 0; i < arg_num; i++) {
2140 uap_printf(MSG_DEBUG, "\tDBG:Argument %d. %s\n", i + 1, args[i]);
2143 /* Check for end of AP configurations */
2144 if (is_ap_config == 1) {
2145 if (strcmp(args[0], "}") == 0) {
2147 if (tx_data_rate != -1) {
2148 if ((!rate[0]) && (tx_data_rate) &&
2149 (is_tx_rate_valid((u8) tx_data_rate) != UAP_SUCCESS)) {
2150 printf("ERR: Invalid Tx Data Rate \n");
2153 if (rate[0] && tx_data_rate) {
2154 for (i = 0; rate[i] != 0; i++) {
2155 if ((rate[i] & ~BASIC_RATE_SET_BIT) == tx_data_rate) {
2161 printf("ERR: Invalid Tx Data Rate \n");
2166 /* Append a new TLV */
2167 TLVBUF_TX_DATA_RATE *tlv = NULL;
2168 tlv_len = sizeof(TLVBUF_TX_DATA_RATE);
2169 buffer = realloc(buffer, cmd_len + tlv_len);
2171 printf("ERR:Cannot append tx data rate TLV!\n");
2174 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2175 tlv = (TLVBUF_TX_DATA_RATE *) (buffer + cmd_len);
2177 /* Set TLV fields */
2178 tlv->Tag = MRVL_TX_DATA_RATE_TLV_ID;
2180 tlv->TxDataRate = tx_data_rate;
2181 endian_convert_tlv_header_out(tlv);
2182 tlv->TxDataRate = uap_cpu_to_le16(tlv->TxDataRate);
2184 if (mcbc_data_rate != -1) {
2185 if ((!rate[0]) && (mcbc_data_rate) &&
2186 (is_mcbc_rate_valid((u8) mcbc_data_rate) !=
2188 printf("ERR: Invalid Tx Data Rate \n");
2191 if (rate[0] && mcbc_data_rate) {
2192 for (i = 0; rate[i] != 0; i++) {
2193 if (rate[i] & BASIC_RATE_SET_BIT) {
2194 if ((rate[i] & ~BASIC_RATE_SET_BIT) ==
2202 printf("ERR: Invalid MCBC Data Rate \n");
2207 /* Append a new TLV */
2208 TLVBUF_MCBC_DATA_RATE *tlv = NULL;
2209 tlv_len = sizeof(TLVBUF_MCBC_DATA_RATE);
2210 buffer = realloc(buffer, cmd_len + tlv_len);
2212 printf("ERR:Cannot append tx data rate TLV!\n");
2215 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2216 tlv = (TLVBUF_MCBC_DATA_RATE *) (buffer + cmd_len);
2218 /* Set TLV fields */
2219 tlv->Tag = MRVL_MCBC_DATA_RATE_TLV_ID;
2221 tlv->MCBCdatarate = mcbc_data_rate;
2222 endian_convert_tlv_header_out(tlv);
2223 tlv->MCBCdatarate = uap_cpu_to_le16(tlv->MCBCdatarate);
2226 if ((pairwisecipher >= 0) && (groupcipher >= 0)) {
2227 if (is_cipher_valid(pairwisecipher, groupcipher) !=
2230 ("ERR:Wrong group and pair cipher combination!\n");
2233 TLVBUF_CIPHER *tlv = NULL;
2234 /* Append a new TLV */
2235 tlv_len = sizeof(TLVBUF_CIPHER);
2236 buffer = realloc(buffer, cmd_len + tlv_len);
2238 printf("ERR:Cannot append cipher TLV!\n");
2241 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2242 tlv = (TLVBUF_CIPHER *) (buffer + cmd_len);
2243 bzero((char *) tlv, tlv_len);
2245 /* Set TLV fields */
2246 tlv->Tag = MRVL_CIPHER_TLV_ID;
2248 tlv->PairwiseCipher = pairwisecipher;
2249 tlv->GroupCipher = groupcipher;
2250 endian_convert_tlv_header_out(tlv);
2252 cmd_buf->Size = cmd_len;
2253 /* Send collective command */
2254 uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
2264 /* Check for beginning of AP configurations */
2265 if (strcmp(args[0], "ap_config") == 0) {
2267 cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE);
2272 buffer = (u8 *) malloc(cmd_len);
2274 printf("ERR:Cannot allocate memory!\n");
2277 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2278 cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
2279 cmd_buf->Size = cmd_len;
2280 cmd_buf->SeqNum = 0;
2281 cmd_buf->Result = 0;
2282 cmd_buf->Action = ACTION_SET;
2286 /* Check for end of AP MAC address filter configurations */
2287 if (is_ap_mac_filter == 1) {
2288 if (strcmp(args[0], "}") == 0) {
2289 is_ap_mac_filter = 0;
2290 if (filter_tlv->Count != filter_mac_count) {
2292 ("ERR:Number of MAC address provided does not match 'Count'\n");
2295 if (filter_tlv->FilterMode && (filter_tlv->Count == 0)) {
2297 ("ERR:Filter list can not be empty for %s Filter mode\n",
2298 (filter_tlv->FilterMode == 1) ? "'Allow'" : "'Block'");
2301 filter_tlv->Length = (filter_tlv->Count * ETH_ALEN) + 2;
2303 (MAX_MAC_ONESHOT_FILTER - filter_mac_count) * ETH_ALEN;
2304 cmd_buf->Size = cmd_len;
2305 endian_convert_tlv_header_out(filter_tlv);
2306 uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
2316 /* Check for end of custom IE configurations */
2317 if (is_custom_ie_config == 1) {
2318 if (strcmp(args[0], "}") == 0) {
2319 if (custom_mask_count != custom_buf_count) {
2321 ("ERR:custom IE mask count and buffer count does not match\n");
2324 is_custom_ie_config = 0;
2325 custom_ie_tlv_head->Length = custom_ie_tlv_len;
2327 (MAX_IE_BUFFER_LEN * MAX_CUSTOM_IE_COUNT) -
2329 cmd_len -= sizeof(custom_ie) * MAX_CUSTOM_IE_COUNT;
2330 cmd_buf->Size = cmd_len;
2331 endian_convert_tlv_header_out(custom_ie_tlv_head);
2332 uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
2342 if (flag_80211d && (strcmp(args[0], "11d_enable") == 0)) {
2343 if (IS_HEX_OR_DIGIT(args[1]) == UAP_FAILURE) {
2344 printf("ERR: valid input for state are 0 or 1\n");
2347 state_80211d = (u8) A2HEXDECIMAL(args[1]);
2349 if ((state_80211d != 0) && (state_80211d != 1)) {
2350 printf("ERR: valid input for state are 0 or 1 \n");
2354 (ACTION_SET, OID_80211D_ENABLE, sizeof(state_80211d),
2361 if (strcmp(args[0], "country") == 0) {
2362 APCMDBUF_CFG_80211D *cmd_buf = NULL;
2363 IEEEtypes_SubbandSet_t sub_bands[MAX_SUB_BANDS];
2364 u8 no_of_sub_band = 0;
2369 if ((strlen(args[1]) > 3) || (strlen(args[1]) < 0)) {
2370 printf("In-correct country input\n");
2373 strcpy(country_80211d, args[1]);
2374 for (i = 0; i < strlen(country_80211d); i++) {
2375 if ((country_80211d[i] < 'A') || (country_80211d[i] > 'z')) {
2376 printf("Invalid Country Code\n");
2379 if (country_80211d[i] > 'Z')
2380 country_80211d[i] = country_80211d[i] - 'a' + 'A';
2382 no_of_sub_band = parse_domain_file(country_80211d, sub_bands);
2383 if (no_of_sub_band == UAP_FAILURE) {
2384 printf("Parsing Failed\n");
2387 buf_len = sizeof(APCMDBUF_CFG_80211D);
2388 buf_len += no_of_sub_band * sizeof(IEEEtypes_SubbandSet_t);
2389 buf = (u8 *) malloc(buf_len);
2391 printf("ERR:Cannot allocate buffer from command!\n");
2394 bzero((char *) buf, buf_len);
2395 cmd_buf = (APCMDBUF_CFG_80211D *) buf;
2397 cmd_buf->Size = cmdlen - BUF_HEADER_SIZE;
2398 cmd_buf->Result = 0;
2399 cmd_buf->SeqNum = 0;
2400 cmd_buf->Action = uap_cpu_to_le16(ACTION_SET);
2401 cmd_buf->CmdCode = HostCmd_CMD_802_11D_DOMAIN_INFO;
2402 cmd_buf->Domain.Tag = uap_cpu_to_le16(TLV_TYPE_DOMAIN);
2403 cmd_buf->Domain.Length = uap_cpu_to_le16(sizeof(domain_param_t)
2408 (IEEEtypes_SubbandSet_t)));
2410 memset(cmd_buf->Domain.CountryCode, ' ',
2411 sizeof(cmd_buf->Domain.CountryCode));
2412 memcpy(cmd_buf->Domain.CountryCode, country_80211d,
2413 strlen(country_80211d));
2414 memcpy(cmd_buf->Domain.Subband, sub_bands,
2415 no_of_sub_band * sizeof(IEEEtypes_SubbandSet_t));
2417 /* Send the command */
2418 uap_ioctl((u8 *) cmd_buf, &cmdlen, buf_len);
2423 /* Check for beginning of AP MAC address filter configurations */
2424 if (strcmp(args[0], "ap_mac_filter") == 0) {
2425 is_ap_mac_filter = 1;
2427 sizeof(APCMDBUF_SYS_CONFIGURE) +
2428 sizeof(TLVBUF_STA_MAC_ADDR_FILTER) +
2429 (MAX_MAC_ONESHOT_FILTER * ETH_ALEN);
2434 buffer = (u8 *) malloc(cmd_len);
2436 printf("ERR:Cannot allocate memory!\n");
2439 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2440 cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
2441 cmd_buf->Size = cmd_len;
2442 cmd_buf->SeqNum = 0;
2443 cmd_buf->Result = 0;
2444 cmd_buf->Action = ACTION_SET;
2446 (TLVBUF_STA_MAC_ADDR_FILTER *) (buffer +
2447 sizeof(APCMDBUF_SYS_CONFIGURE));
2448 filter_tlv->Tag = MRVL_STA_MAC_ADDR_FILTER_TLV_ID;
2449 filter_tlv->Length = 2;
2450 filter_tlv->Count = 0;
2451 filter_mac_count = 0;
2455 /* Check for beginning of custom IE configurations */
2456 if (strcmp(args[0], "custom_ie_config") == 0) {
2457 is_custom_ie_config = 1;
2458 cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE) + sizeof(tlvbuf_custom_ie)
2460 ((MAX_IE_BUFFER_LEN + sizeof(custom_ie)) * MAX_CUSTOM_IE_COUNT);
2465 buffer = (u8 *) malloc(cmd_len);
2467 printf("ERR:Cannot allocate memory!\n");
2470 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2471 cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
2472 cmd_buf->Size = cmd_len;
2473 cmd_buf->SeqNum = 0;
2474 cmd_buf->Result = 0;
2475 cmd_buf->Action = ACTION_SET;
2477 (tlvbuf_custom_ie *) (buffer + sizeof(APCMDBUF_SYS_CONFIGURE));
2478 custom_ie_ptr = (custom_ie *) (custom_ie_tlv->ie_data);
2479 custom_ie_tlv_head = custom_ie_tlv;
2480 custom_ie_tlv_head->Tag = MRVL_MGMT_IE_LIST_TLV_ID;
2484 if ((strcmp(args[0], "FilterMode") == 0) && is_ap_mac_filter) {
2485 if ((ISDIGIT(args[1]) == 0) || (atoi(args[1]) < 0) ||
2486 (atoi(args[1]) > 2)) {
2488 ("ERR:Illegal FilterMode paramter %d. Must be either '0', '1', or '2'.\n",
2492 filter_tlv->FilterMode = atoi(args[1]);
2495 if ((strcmp(args[0], "Count") == 0) && is_ap_mac_filter) {
2496 filter_tlv->Count = atoi(args[1]);
2497 if ((ISDIGIT(args[1]) == 0) ||
2498 (filter_tlv->Count > MAX_MAC_ONESHOT_FILTER)) {
2499 printf("ERR: Illegal Count parameter.\n");
2503 if ((strncmp(args[0], "mac_", 4) == 0) && is_ap_mac_filter) {
2504 if (filter_mac_count < MAX_MAC_ONESHOT_FILTER) {
2507 &filter_tlv->MacAddress[filter_mac_count * ETH_ALEN]) !=
2509 printf("ERR: Invalid MAC address %s \n", args[1]);
2515 ("ERR: Filter table can not have more than %d MAC addresses\n",
2516 MAX_MAC_ONESHOT_FILTER);
2521 /* custom ie configuration parameters */
2522 if ((strncmp(args[0], "MgmtSubtypeMask_", 16) == 0) &&
2523 is_custom_ie_config) {
2524 if (UAP_FAILURE == ishexstring(args[1])) {
2525 printf("ERR:Illegal MgmtSubtypeMask %s.\n", args[1]);
2528 mask_ie_index = (u16) atoi(args[0] + strlen("MgmtSubtypeMask_"));
2529 if (mask_ie_index > 3) {
2530 printf("ERR:Incorrect index %d.\n", mask_ie_index);
2533 custom_ie_ptr->ie_index = uap_cpu_to_le16(mask_ie_index);
2534 custom_ie_ptr->mgmt_subtype_mask = (u16) A2HEXDECIMAL(args[1]);
2535 custom_ie_ptr->mgmt_subtype_mask = uap_cpu_to_le16
2536 (custom_ie_ptr->mgmt_subtype_mask);
2537 custom_mask_count++;
2540 if ((strncmp(args[0], "IEBuffer_", 9) == 0) && is_custom_ie_config) {
2541 if (UAP_FAILURE == ishexstring(args[1])) {
2542 printf("ERR:Only hex digits are allowed\n");
2545 ie_buf_len = strlen(args[1]);
2546 if (!strncasecmp("0x", args[1], 2)) {
2547 ie_len = (ie_buf_len - 2 + 1) / 2;
2550 ie_len = (ie_buf_len + 1) / 2;
2552 if (ie_len > MAX_IE_BUFFER_LEN) {
2553 printf("ERR:Incorrect IE length %d\n", ie_buf_len);
2557 custom_ie_ptr->ie_index = (u16) atoi(args[0] + strlen("IEBuffer_"));
2558 if (custom_ie_ptr->ie_index != mask_ie_index) {
2559 printf("ERR:IE buffer%d should follow MgmtSubtypeMask%d\n",
2560 mask_ie_index, mask_ie_index);
2563 custom_ie_ptr->ie_index = uap_cpu_to_le16(custom_ie_ptr->ie_index);
2564 string2raw(args[1], custom_ie_ptr->ie_buffer);
2565 custom_ie_ptr->ie_length = uap_cpu_to_le16(ie_len);
2566 custom_ie_tlv_len += sizeof(custom_ie) + ie_len;
2567 custom_ie_tlv = (tlvbuf_custom_ie *) ((u8 *) custom_ie_tlv
2568 + sizeof(custom_ie) + ie_len);
2569 custom_ie_ptr = (custom_ie *) (custom_ie_tlv->ie_data);
2573 if (strcmp(args[0], "SSID") == 0) {
2575 printf("ERR:SSID field is blank!\n");
2578 TLVBUF_SSID *tlv = NULL;
2579 if (args[1][0] == '"') {
2582 if (args[1][strlen(args[1]) - 1] == '"') {
2583 args[1][strlen(args[1]) - 1] = '\0';
2585 if ((strlen(args[1]) > MAX_SSID_LENGTH) ||
2586 (strlen(args[1]) == 0)) {
2587 printf("ERR:SSID length out of range (%d to %d).\n",
2588 MIN_SSID_LENGTH, MAX_SSID_LENGTH);
2591 /* Append a new TLV */
2592 tlv_len = sizeof(TLVBUF_SSID) + strlen(args[1]);
2593 buffer = realloc(buffer, cmd_len + tlv_len);
2595 printf("ERR:Cannot realloc SSID TLV!\n");
2598 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2599 tlv = (TLVBUF_SSID *) (buffer + cmd_len);
2601 /* Set TLV fields */
2602 tlv->Tag = MRVL_SSID_TLV_ID;
2603 tlv->Length = strlen(args[1]);
2604 memcpy(tlv->Ssid, args[1], tlv->Length);
2605 endian_convert_tlv_header_out(tlv);
2608 if (strcmp(args[0], "BeaconPeriod") == 0) {
2609 if (is_input_valid(BEACONPERIOD, arg_num - 1, args + 1) !=
2613 TLVBUF_BEACON_PERIOD *tlv = NULL;
2614 /* Append a new TLV */
2615 tlv_len = sizeof(TLVBUF_BEACON_PERIOD);
2616 buffer = realloc(buffer, cmd_len + tlv_len);
2618 printf("ERR:Cannot realloc beacon period TLV!\n");
2621 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2622 tlv = (TLVBUF_BEACON_PERIOD *) (buffer + cmd_len);
2624 /* Set TLV fields */
2625 tlv->Tag = MRVL_BEACON_PERIOD_TLV_ID;
2627 tlv->BeaconPeriod_ms = (u16) atoi(args[1]);
2628 endian_convert_tlv_header_out(tlv);
2629 tlv->BeaconPeriod_ms = uap_cpu_to_le16(tlv->BeaconPeriod_ms);
2631 if (strcmp(args[0], "ChanList") == 0) {
2632 if (is_input_valid(SCANCHANNELS, arg_num - 1, args + 1) !=
2637 TLVBUF_CHANNEL_LIST *tlv = NULL;
2638 CHANNEL_LIST *pChanList = NULL;
2639 /* Append a new TLV */
2641 sizeof(TLVBUF_CHANNEL_LIST) +
2642 ((arg_num - 1) * sizeof(CHANNEL_LIST));
2643 buffer = realloc(buffer, cmd_len + tlv_len);
2645 printf("ERR:Cannot append channel list TLV!\n");
2648 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2649 tlv = (TLVBUF_CHANNEL_LIST *) (buffer + cmd_len);
2651 /* Set TLV fields */
2652 tlv->Tag = MRVL_CHANNELLIST_TLV_ID;
2653 tlv->Length = sizeof(CHANNEL_LIST) * (arg_num - 1);
2654 pChanList = (CHANNEL_LIST *) tlv->ChanList;
2655 for (i = 0; i < (arg_num - 1); i++) {
2656 pChanList->ChanNumber = (u8) atoi(args[i + 1]);
2657 pChanList->BandConfigType = 0;
2660 endian_convert_tlv_header_out(tlv);
2662 if (strcmp(args[0], "Channel") == 0) {
2663 if (is_input_valid(CHANNEL, arg_num - 1, args + 1) != UAP_SUCCESS) {
2666 TLVBUF_CHANNEL_CONFIG *tlv = NULL;
2667 /* Append a new TLV */
2668 tlv_len = sizeof(TLVBUF_CHANNEL_CONFIG);
2669 buffer = realloc(buffer, cmd_len + tlv_len);
2671 printf("ERR:Cannot append channel TLV!\n");
2674 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2675 tlv = (TLVBUF_CHANNEL_CONFIG *) (buffer + cmd_len);
2677 /* Set TLV fields */
2678 tlv->Tag = MRVL_CHANNELCONFIG_TLV_ID;
2680 tlv->ChanNumber = (u8) atoi(args[1]);
2681 if ((arg_num - 1) == 2)
2682 tlv->BandConfigType = atoi(args[2]) ? BAND_CONFIG_ACS_MODE : 0;
2684 tlv->BandConfigType = 0;
2685 endian_convert_tlv_header_out(tlv);
2687 if (strcmp(args[0], "AP_MAC") == 0) {
2689 TLVBUF_AP_MAC_ADDRESS *tlv = NULL;
2690 /* Append a new TLV */
2691 tlv_len = sizeof(TLVBUF_AP_MAC_ADDRESS);
2692 buffer = realloc(buffer, cmd_len + tlv_len);
2694 printf("ERR:Cannot append channel TLV!\n");
2697 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2698 tlv = (TLVBUF_AP_MAC_ADDRESS *) (buffer + cmd_len);
2700 cmd_buf->Action = ACTION_SET;
2701 tlv->Tag = MRVL_AP_MAC_ADDRESS_TLV_ID;
2702 tlv->Length = ETH_ALEN;
2703 if ((ret = mac2raw(args[1], tlv->ApMacAddr)) != UAP_SUCCESS) {
2704 printf("ERR: %s Address \n",
2705 ret == UAP_FAILURE ? "Invalid MAC" : ret ==
2706 UAP_RET_MAC_BROADCAST ? "Broadcast" : "Multicast");
2709 endian_convert_tlv_header_out(tlv);
2712 if (strcmp(args[0], "RxAntenna") == 0) {
2713 if ((ISDIGIT(args[1]) != UAP_SUCCESS) || (atoi(args[1]) < 0) ||
2714 (atoi(args[1]) > 1)) {
2715 printf("ERR: Invalid Antenna value\n");
2718 TLVBUF_ANTENNA_CTL *tlv = NULL;
2719 /* Append a new TLV */
2720 tlv_len = sizeof(TLVBUF_ANTENNA_CTL);
2721 buffer = realloc(buffer, cmd_len + tlv_len);
2723 printf("ERR:Cannot append channel TLV!\n");
2726 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2727 tlv = (TLVBUF_ANTENNA_CTL *) (buffer + cmd_len);
2729 cmd_buf->Action = ACTION_SET;
2730 tlv->Tag = MRVL_ANTENNA_CTL_TLV_ID;
2732 tlv->WhichAntenna = 0;
2733 tlv->AntennaMode = atoi(args[1]);
2734 endian_convert_tlv_header_out(tlv);
2737 if (strcmp(args[0], "TxAntenna") == 0) {
2738 if ((ISDIGIT(args[1]) != UAP_SUCCESS) || (atoi(args[1]) < 0) ||
2739 (atoi(args[1]) > 1)) {
2740 printf("ERR: Invalid Antenna value\n");
2743 TLVBUF_ANTENNA_CTL *tlv = NULL;
2744 /* Append a new TLV */
2745 tlv_len = sizeof(TLVBUF_ANTENNA_CTL);
2746 buffer = realloc(buffer, cmd_len + tlv_len);
2748 printf("ERR:Cannot append channel TLV!\n");
2751 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2752 tlv = (TLVBUF_ANTENNA_CTL *) (buffer + cmd_len);
2754 cmd_buf->Action = ACTION_SET;
2755 tlv->Tag = MRVL_ANTENNA_CTL_TLV_ID;
2757 tlv->WhichAntenna = 1;
2758 tlv->AntennaMode = atoi(args[1]);
2759 endian_convert_tlv_header_out(tlv);
2761 if (strcmp(args[0], "Rate") == 0) {
2762 if (is_input_valid(RATE, arg_num - 1, args + 1) != UAP_SUCCESS) {
2763 printf("ERR: Invalid Rate input\n");
2766 TLVBUF_RATES *tlv = NULL;
2767 /* Append a new TLV */
2768 tlv_len = sizeof(TLVBUF_RATES) + arg_num - 1;
2769 buffer = realloc(buffer, cmd_len + tlv_len);
2771 printf("ERR:Cannot append rates TLV!\n");
2774 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2775 tlv = (TLVBUF_RATES *) (buffer + cmd_len);
2777 /* Set TLV fields */
2778 tlv->Tag = MRVL_RATES_TLV_ID;
2779 tlv->Length = arg_num - 1;
2780 for (i = 0; i < tlv->Length; i++) {
2781 rate[i] = tlv->OperationalRates[i] =
2782 (u8) A2HEXDECIMAL(args[i + 1]);
2784 endian_convert_tlv_header_out(tlv);
2786 if (strcmp(args[0], "TxPowerLevel") == 0) {
2787 if (is_input_valid(TXPOWER, arg_num - 1, args + 1) != UAP_SUCCESS) {
2788 printf("ERR:Invalid TxPowerLevel \n");
2791 TLVBUF_TX_POWER *tlv = NULL;
2792 /* Append a new TLV */
2793 tlv_len = sizeof(TLVBUF_TX_POWER);
2794 buffer = realloc(buffer, cmd_len + tlv_len);
2796 printf("ERR:Cannot append tx power level TLV!\n");
2799 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2800 tlv = (TLVBUF_TX_POWER *) (buffer + cmd_len);
2802 /* Set TLV fields */
2803 tlv->Tag = MRVL_TX_POWER_TLV_ID;
2805 tlv->TxPower_dBm = (u8) atoi(args[1]);
2806 endian_convert_tlv_header_out(tlv);
2809 if (strcmp(args[0], "BroadcastSSID") == 0) {
2810 if (is_input_valid(BROADCASTSSID, arg_num - 1, args + 1) !=
2814 TLVBUF_BCAST_SSID_CTL *tlv = NULL;
2815 /* Append a new TLV */
2816 tlv_len = sizeof(TLVBUF_BCAST_SSID_CTL);
2817 buffer = realloc(buffer, cmd_len + tlv_len);
2819 printf("ERR:Cannot append SSID broadcast control TLV!\n");
2822 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2823 tlv = (TLVBUF_BCAST_SSID_CTL *) (buffer + cmd_len);
2825 /* Set TLV fields */
2826 tlv->Tag = MRVL_BCAST_SSID_CTL_TLV_ID;
2828 tlv->BcastSsidCtl = (u8) atoi(args[1]);
2829 endian_convert_tlv_header_out(tlv);
2831 if (strcmp(args[0], "RTSThreshold") == 0) {
2832 if (is_input_valid(RTSTHRESH, arg_num - 1, args + 1) != UAP_SUCCESS) {
2835 TLVBUF_RTS_THRESHOLD *tlv = NULL;
2836 /* Append a new TLV */
2837 tlv_len = sizeof(TLVBUF_RTS_THRESHOLD);
2838 buffer = realloc(buffer, cmd_len + tlv_len);
2840 printf("ERR:Cannot append RTS threshold TLV!\n");
2843 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2844 tlv = (TLVBUF_RTS_THRESHOLD *) (buffer + cmd_len);
2846 /* Set TLV fields */
2847 tlv->Tag = MRVL_RTS_THRESHOLD_TLV_ID;
2849 tlv->RtsThreshold = (u16) atoi(args[1]);
2850 endian_convert_tlv_header_out(tlv);
2851 tlv->RtsThreshold = uap_cpu_to_le16(tlv->RtsThreshold);
2853 if (strcmp(args[0], "FragThreshold") == 0) {
2854 if (is_input_valid(FRAGTHRESH, arg_num - 1, args + 1) !=
2858 TLVBUF_FRAG_THRESHOLD *tlv = NULL;
2859 /* Append a new TLV */
2860 tlv_len = sizeof(TLVBUF_FRAG_THRESHOLD);
2861 buffer = realloc(buffer, cmd_len + tlv_len);
2863 printf("ERR:Cannot append Fragmentation threshold TLV!\n");
2866 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2867 tlv = (TLVBUF_FRAG_THRESHOLD *) (buffer + cmd_len);
2869 /* Set TLV fields */
2870 tlv->Tag = MRVL_FRAG_THRESHOLD_TLV_ID;
2872 tlv->FragThreshold = (u16) atoi(args[1]);
2873 endian_convert_tlv_header_out(tlv);
2874 tlv->FragThreshold = uap_cpu_to_le16(tlv->FragThreshold);
2876 if (strcmp(args[0], "DTIMPeriod") == 0) {
2877 if (is_input_valid(DTIMPERIOD, arg_num - 1, args + 1) !=
2881 TLVBUF_DTIM_PERIOD *tlv = NULL;
2882 /* Append a new TLV */
2883 tlv_len = sizeof(TLVBUF_DTIM_PERIOD);
2884 buffer = realloc(buffer, cmd_len + tlv_len);
2886 printf("ERR:Cannot append DTIM period TLV!\n");
2889 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2890 tlv = (TLVBUF_DTIM_PERIOD *) (buffer + cmd_len);
2892 /* Set TLV fields */
2893 tlv->Tag = MRVL_DTIM_PERIOD_TLV_ID;
2895 tlv->DtimPeriod = (u8) atoi(args[1]);
2896 endian_convert_tlv_header_out(tlv);
2898 if (strcmp(args[0], "RadioControl") == 0) {
2899 if (is_input_valid(RADIOCONTROL, arg_num - 1, args + 1) !=
2903 TLVBUF_RADIO_CTL *tlv = NULL;
2904 /* Append a new TLV */
2905 tlv_len = sizeof(TLVBUF_RADIO_CTL);
2906 buffer = realloc(buffer, cmd_len + tlv_len);
2908 printf("ERR:Cannot append radio control TLV!\n");
2911 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2912 tlv = (TLVBUF_RADIO_CTL *) (buffer + cmd_len);
2914 /* Set TLV fields */
2915 tlv->Tag = MRVL_RADIO_CTL_TLV_ID;
2917 tlv->RadioCtl = (u8) atoi(args[1]);
2918 endian_convert_tlv_header_out(tlv);
2920 if (strcmp(args[0], "RSNReplayProtection") == 0) {
2921 if (is_input_valid(RSNREPLAYPROT, arg_num - 1, args + 1) !=
2925 tlvbuf_rsn_replay_prot *tlv = NULL;
2926 /* Append a new TLV */
2927 tlv_len = sizeof(tlvbuf_rsn_replay_prot);
2928 buffer = realloc(buffer, cmd_len + tlv_len);
2930 printf("ERR:Cannot append RSN replay protection TLV!\n");
2933 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2934 tlv = (tlvbuf_rsn_replay_prot *) (buffer + cmd_len);
2936 /* Set TLV fields */
2937 tlv->Tag = MRVL_RSN_REPLAY_PROT_TLV_ID;
2939 tlv->rsn_replay_prot = (u8) atoi(args[1]);
2940 endian_convert_tlv_header_out(tlv);
2942 if (strcmp(args[0], "TxDataRate") == 0) {
2943 if (is_input_valid(TXDATARATE, arg_num - 1, args + 1) !=
2947 tx_data_rate = (u16) A2HEXDECIMAL(args[1]);
2949 if (strcmp(args[0], "MCBCdataRate") == 0) {
2950 if (is_input_valid(MCBCDATARATE, arg_num - 1, args + 1) !=
2954 mcbc_data_rate = (u16) A2HEXDECIMAL(args[1]);
2956 if (strcmp(args[0], "PktFwdCtl") == 0) {
2957 if (is_input_valid(PKTFWD, arg_num - 1, args + 1) != UAP_SUCCESS) {
2960 TLVBUF_PKT_FWD_CTL *tlv = NULL;
2961 /* Append a new TLV */
2962 tlv_len = sizeof(TLVBUF_PKT_FWD_CTL);
2963 buffer = realloc(buffer, cmd_len + tlv_len);
2965 printf("ERR:Cannot append packet forwarding control TLV!\n");
2968 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2969 tlv = (TLVBUF_PKT_FWD_CTL *) (buffer + cmd_len);
2971 /* Set TLV fields */
2972 tlv->Tag = MRVL_PKT_FWD_CTL_TLV_ID;
2974 tlv->PktFwdCtl = (u8) atoi(args[1]);
2975 endian_convert_tlv_header_out(tlv);
2977 if (strcmp(args[0], "StaAgeoutTimer") == 0) {
2978 if (is_input_valid(STAAGEOUTTIMER, arg_num - 1, args + 1) !=
2982 TLVBUF_STA_AGEOUT_TIMER *tlv = NULL;
2983 /* Append a new TLV */
2984 tlv_len = sizeof(TLVBUF_STA_AGEOUT_TIMER);
2985 buffer = realloc(buffer, cmd_len + tlv_len);
2987 printf("ERR:Cannot append STA ageout timer TLV!\n");
2990 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
2991 tlv = (TLVBUF_STA_AGEOUT_TIMER *) (buffer + cmd_len);
2993 /* Set TLV fields */
2994 tlv->Tag = MRVL_STA_AGEOUT_TIMER_TLV_ID;
2996 tlv->StaAgeoutTimer_ms = (u32) atoi(args[1]);
2997 endian_convert_tlv_header_out(tlv);
2998 tlv->StaAgeoutTimer_ms = uap_cpu_to_le32(tlv->StaAgeoutTimer_ms);
3000 if (strcmp(args[0], "AuthMode") == 0) {
3001 if (is_input_valid(AUTHMODE, arg_num - 1, args + 1) != UAP_SUCCESS) {
3004 TLVBUF_AUTH_MODE *tlv = NULL;
3005 if ((atoi(args[1]) < 0) || (atoi(args[1]) > 1)) {
3007 ("ERR:Illegal AuthMode parameter. Must be either '0' or '1'.\n");
3010 /* Append a new TLV */
3011 tlv_len = sizeof(TLVBUF_AUTH_MODE);
3012 buffer = realloc(buffer, cmd_len + tlv_len);
3014 printf("ERR:Cannot append auth mode TLV!\n");
3017 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3018 tlv = (TLVBUF_AUTH_MODE *) (buffer + cmd_len);
3020 /* Set TLV fields */
3021 tlv->Tag = MRVL_AUTH_TLV_ID;
3023 tlv->AuthMode = (u8) atoi(args[1]);
3024 endian_convert_tlv_header_out(tlv);
3026 if (strcmp(args[0], "KeyIndex") == 0) {
3028 printf("KeyIndex is blank!\n");
3031 if (ISDIGIT(args[1]) == 0) {
3033 ("ERR:Illegal KeyIndex parameter. Must be either '0', '1', '2', or '3'.\n");
3036 keyindex = atoi(args[1]);
3037 if ((keyindex < 0) || (keyindex > 3)) {
3039 ("ERR:Illegal KeyIndex parameter. Must be either '0', '1', '2', or '3'.\n");
3044 if (strncmp(args[0], "Key_", 4) == 0) {
3046 printf("ERR:%s is blank!\n", args[0]);
3049 TLVBUF_WEP_KEY *tlv = NULL;
3051 if (args[1][0] == '"') {
3052 if ((strlen(args[1]) != 2) && (strlen(args[1]) != 7) &&
3053 (strlen(args[1]) != 15)) {
3054 printf("ERR:Wrong key length!\n");
3057 key_len = strlen(args[1]) - 2;
3059 if ((strlen(args[1]) != 0) && (strlen(args[1]) != 10) &&
3060 (strlen(args[1]) != 26)) {
3061 printf("ERR:Wrong key length!\n");
3064 if (UAP_FAILURE == ishexstring(args[1])) {
3066 ("ERR:Only hex digits are allowed when key length is 10 or 26\n");
3069 key_len = strlen(args[1]) / 2;
3071 /* Append a new TLV */
3072 tlv_len = sizeof(TLVBUF_WEP_KEY) + key_len;
3073 buffer = realloc(buffer, cmd_len + tlv_len);
3075 printf("ERR:Cannot append WEP key configurations TLV!\n");
3078 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3079 tlv = (TLVBUF_WEP_KEY *) (buffer + cmd_len);
3081 /* Set TLV fields */
3082 tlv->Tag = MRVL_WEP_KEY_TLV_ID;
3083 tlv->Length = key_len + 2;
3084 if (strcmp(args[0], "Key_0") == 0) {
3086 } else if (strcmp(args[0], "Key_1") == 0) {
3088 } else if (strcmp(args[0], "Key_2") == 0) {
3090 } else if (strcmp(args[0], "Key_3") == 0) {
3093 if (keyindex == tlv->KeyIndex) {
3098 if (args[1][0] == '"') {
3099 memcpy(tlv->Key, &args[1][1], strlen(args[1]) - 2);
3101 string2raw(args[1], tlv->Key);
3103 endian_convert_tlv_header_out(tlv);
3106 if (strcmp(args[0], "PSK") == 0) {
3108 printf("ERR:PSK is blank!\n");
3111 TLVBUF_WPA_PASSPHRASE *tlv = NULL;
3112 if (args[1][0] == '"') {
3115 if (args[1][strlen(args[1]) - 1] == '"') {
3116 args[1][strlen(args[1]) - 1] = '\0';
3118 tlv_len = sizeof(TLVBUF_WPA_PASSPHRASE) + strlen(args[1]);
3119 if (strlen(args[1]) > MAX_WPA_PASSPHRASE_LENGTH) {
3120 printf("ERR:PSK too long.\n");
3123 if (strlen(args[1]) < MIN_WPA_PASSPHRASE_LENGTH) {
3124 printf("ERR:PSK too short.\n");
3127 if (strlen(args[1]) == MAX_WPA_PASSPHRASE_LENGTH) {
3128 if (UAP_FAILURE == ishexstring(args[1])) {
3130 ("ERR:Only hex digits are allowed when passphrase's length is 64\n");
3134 /* Append a new TLV */
3135 buffer = realloc(buffer, cmd_len + tlv_len);
3137 printf("ERR:Cannot append WPA passphrase TLV!\n");
3140 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3141 tlv = (TLVBUF_WPA_PASSPHRASE *) (buffer + cmd_len);
3143 /* Set TLV fields */
3144 tlv->Tag = MRVL_WPA_PASSPHRASE_TLV_ID;
3145 tlv->Length = strlen(args[1]);
3146 memcpy(tlv->Passphrase, args[1], tlv->Length);
3147 endian_convert_tlv_header_out(tlv);
3150 if (strcmp(args[0], "Protocol") == 0) {
3151 if (is_input_valid(PROTOCOL, arg_num - 1, args + 1) != UAP_SUCCESS) {
3154 TLVBUF_PROTOCOL *tlv = NULL;
3155 /* Append a new TLV */
3156 tlv_len = sizeof(TLVBUF_PROTOCOL);
3157 buffer = realloc(buffer, cmd_len + tlv_len);
3159 printf("ERR:Cannot append protocol TLV!\n");
3162 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3163 tlv = (TLVBUF_PROTOCOL *) (buffer + cmd_len);
3165 /* Set TLV fields */
3166 tlv->Tag = MRVL_PROTOCOL_TLV_ID;
3168 tlv->Protocol = (u16) atoi(args[1]);
3169 endian_convert_tlv_header_out(tlv);
3170 tlv->Protocol = uap_cpu_to_le16(tlv->Protocol);
3171 if (atoi(args[1]) & (PROTOCOL_WPA | PROTOCOL_WPA2)) {
3172 TLVBUF_AKMP *tlv = NULL;
3173 /* Append a new TLV */
3174 tlv_len = sizeof(TLVBUF_AKMP);
3175 buffer = realloc(buffer, cmd_len + tlv_len);
3177 printf("ERR:Cannot append AKMP TLV!\n");
3180 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3181 tlv = (TLVBUF_AKMP *) (buffer + cmd_len);
3183 /* Set TLV fields */
3184 tlv->Tag = MRVL_AKMP_TLV_ID;
3186 tlv->KeyMgmt = KEY_MGMT_PSK;
3187 endian_convert_tlv_header_out(tlv);
3188 tlv->KeyMgmt = uap_cpu_to_le16(tlv->KeyMgmt);
3191 if (strcmp(args[0], "PairwiseCipher") == 0) {
3193 printf("ERR:PairwiseCipher is blank!\n");
3196 if (ISDIGIT(args[1]) == 0) {
3198 ("ERR:Illegal PairwiseCipher parameter. Must be either bit '2' or '3'.\n");
3201 pairwisecipher = atoi(args[1]);
3202 if (pairwisecipher & ~CIPHER_BITMAP) {
3204 ("ERR:Illegal PairwiseCipher parameter. Must be either bit '2' or '3'.\n");
3209 if (strcmp(args[0], "GroupCipher") == 0) {
3211 printf("ERR:GroupCipher is blank!\n");
3214 if (ISDIGIT(args[1]) == 0) {
3216 ("ERR:Illegal GroupCipher parameter. Must be either bit '2' or '3'.\n");
3219 groupcipher = atoi(args[1]);
3220 if (groupcipher & ~CIPHER_BITMAP) {
3222 ("ERR:Illegal GroupCipher parameter. Must be either bit '2' or '3'.\n");
3227 if (strcmp(args[0], "GroupRekeyTime") == 0) {
3228 if (is_input_valid(GROUPREKEYTIMER, arg_num - 1, args + 1) !=
3232 TLVBUF_GROUP_REKEY_TIMER *tlv = NULL;
3234 /* Append a new TLV */
3235 tlv_len = sizeof(TLVBUF_GROUP_REKEY_TIMER);
3236 buffer = realloc(buffer, cmd_len + tlv_len);
3238 printf("ERR:Cannot append protocol TLV!\n");
3241 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3242 tlv = (TLVBUF_GROUP_REKEY_TIMER *) (buffer + cmd_len);
3244 /* Set TLV fields */
3245 tlv->Tag = MRVL_GRP_REKEY_TIME_TLV_ID;
3247 tlv->GroupRekeyTime_sec = (u32) atoi(args[1]);
3248 endian_convert_tlv_header_out(tlv);
3249 tlv->GroupRekeyTime_sec = uap_cpu_to_le32(tlv->GroupRekeyTime_sec);
3251 if (strcmp(args[0], "MaxStaNum") == 0) {
3252 if (is_input_valid(MAXSTANUM, arg_num - 1, args + 1) != UAP_SUCCESS) {
3255 TLVBUF_MAX_STA_NUM *tlv = NULL;
3257 /* Append a new TLV */
3258 tlv_len = sizeof(TLVBUF_MAX_STA_NUM);
3259 buffer = realloc(buffer, cmd_len + tlv_len);
3261 printf("ERR:Cannot realloc max station number TLV!\n");
3264 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3265 tlv = (TLVBUF_MAX_STA_NUM *) (buffer + cmd_len);
3267 /* Set TLV fields */
3268 tlv->Tag = MRVL_MAX_STA_CNT_TLV_ID;
3270 tlv->Max_sta_num = (u16) atoi(args[1]);
3271 endian_convert_tlv_header_out(tlv);
3272 tlv->Max_sta_num = uap_cpu_to_le16(tlv->Max_sta_num);
3274 if (strcmp(args[0], "Retrylimit") == 0) {
3275 if (is_input_valid(RETRYLIMIT, arg_num - 1, args + 1) !=
3279 TLVBUF_RETRY_LIMIT *tlv = NULL;
3281 /* Append a new TLV */
3282 tlv_len = sizeof(TLVBUF_RETRY_LIMIT);
3283 buffer = realloc(buffer, cmd_len + tlv_len);
3285 printf("ERR:Cannot realloc retry limit TLV!\n");
3288 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
3289 tlv = (TLVBUF_RETRY_LIMIT *) (buffer + cmd_len);
3291 /* Set TLV fields */
3292 tlv->Tag = MRVL_RETRY_LIMIT_TLV_ID;
3294 tlv->retry_limit = (u8) atoi(args[1]);
3295 endian_convert_tlv_header_out(tlv);
3299 hexdump("Command Buffer", (void *) cmd_buf, cmd_len, ' ');
3304 fclose(config_file);
3312 * @brief Show usage information for the cfg_80211d command
3317 print_apcmd_cfg_80211d_usage(void)
3319 printf("\nUsage: cfg_80211d <state 0/1> <country Country_code> \n");
3324 * @brief Show usage information for the uap_stats command
3329 print_apcmd_uap_stats(void)
3331 printf("Usage: uap_stats \n");
3336 * SNMP MIB OIDs Table
3338 static oids_table snmp_oids[] = {
3339 {0x0b, 4, "dot11LocalTKIPMICFailures"},
3340 {0x0c, 4, "dot11CCMPDecryptErrors"},
3341 {0x0d, 4, "dot11WEPUndecryptableCount"},
3342 {0x0e, 4, "dot11WEPICVErrorCount"},
3343 {0x0f, 4, "dot11DecryptFailureCount"},
3344 {0x12, 4, "dot11FailedCount"},
3345 {0x13, 4, "dot11RetryCount"},
3346 {0x14, 4, "dot11MultipleRetryCount"},
3347 {0x15, 4, "dot11FrameDuplicateCount"},
3348 {0x16, 4, "dot11RTSSuccessCount"},
3349 {0x17, 4, "dot11RTSFailureCount"},
3350 {0x18, 4, "dot11ACKFailureCount"},
3351 {0x19, 4, "dot11ReceivedFragmentCount"},
3352 {0x1a, 4, "dot11MulticastReceivedFrameCount"},
3353 {0x1b, 4, "dot11FCSErrorCount"},
3354 {0x1c, 4, "dot11TransmittedFrameCount"},
3355 {0x1d, 4, "dot11RSNATKIPCounterMeasuresInvoked"},
3356 {0x1e, 4, "dot11RSNA4WayHandshakeFailures"},
3357 {0x1f, 4, "dot11MulticastTransmittedFrameCount"}
3361 * @brief Get uAP stats
3363 * @param argc Number of arguments
3364 * @param argv Pointer to the arguments
3369 apcmd_uap_stats(int argc, char *argv[])
3371 u8 no_of_oids = sizeof(snmp_oids) / sizeof(snmp_oids[0]);
3374 APCMDBUF_SNMP_MIB *cmd_buf = NULL;
3376 TLVBUF_HEADER *tlv = NULL;
3383 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
3386 print_apcmd_uap_stats();
3394 printf("Error: Invalid Input\n");
3395 print_apcmd_uap_stats();
3399 /** Command Header */
3400 buf_len += sizeof(APCMDBUF_SNMP_MIB);
3402 for (i = 0; i < no_of_oids; i++) {
3404 * size of Oid + Oid_value + Oid_size
3406 buf_len += snmp_oids[i].len + sizeof(TLVBUF_HEADER);
3408 buf = (u8 *) malloc(buf_len);
3410 printf("ERR:Cannot allocate buffer from command!\n");
3413 bzero((char *) buf, buf_len);
3415 /* Locate Headers */
3416 cmd_buf = (APCMDBUF_SNMP_MIB *) buf;
3417 cmd_buf->Size = buf_len - BUF_HEADER_SIZE;
3418 cmd_buf->Result = 0;
3419 cmd_buf->SeqNum = 0;
3420 cmd_buf->CmdCode = HostCmd_SNMP_MIB;
3421 cmd_buf->Action = uap_cpu_to_le16(ACTION_GET);
3423 tlv = (TLVBUF_HEADER *) ((u8 *) cmd_buf + sizeof(APCMDBUF_SNMP_MIB));
3424 /* Add oid, oid_size and oid_value for each OID */
3425 for (i = 0; i < no_of_oids; i++) {
3426 /** Copy Index as Oid */
3427 tlv->Type = uap_cpu_to_le16(snmp_oids[i].type);
3428 /** Copy its size */
3429 tlv->Len = uap_cpu_to_le16(snmp_oids[i].len);
3431 tlv = (TLVBUF_HEADER *) & (tlv->Data[snmp_oids[i].len]);
3434 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
3435 if (ret == UAP_SUCCESS) {
3436 if (cmd_buf->Result == CMD_SUCCESS) {
3438 (TLVBUF_HEADER *) ((u8 *) cmd_buf + sizeof(APCMDBUF_SNMP_MIB));
3441 cmd_buf->Size - (sizeof(APCMDBUF_SNMP_MIB) - BUF_HEADER_SIZE);
3443 while (size >= sizeof(TLVBUF_HEADER)) {
3444 tlv->Type = uap_le16_to_cpu(tlv->Type);
3445 for (i = 0; i < no_of_oids; i++) {
3446 if (snmp_oids[i].type == tlv->Type) {
3447 printf("%s: ", snmp_oids[i].name);
3451 oid_size = uap_le16_to_cpu(tlv->Len);
3454 printf("%d", (unsigned int) tlv->Data[0]);
3458 (unsigned int) uap_le16_to_cpu(*(u16 *) tlv->Data));
3462 (unsigned long) uap_le32_to_cpu(*(u32 *) tlv->Data));
3465 for (j = 0; j < oid_size; j++) {
3466 printf("%d ", (u8) tlv->Data[i]);
3471 tlv = (TLVBUF_HEADER *) & (tlv->Data[oid_size]);
3472 size -= (sizeof(TLVBUF_HEADER) + oid_size);
3473 size = (size > 0) ? size : 0;
3478 printf("ERR:Command Response incorrect!\n");
3481 printf("ERR:Command sending failed!\n");
3487 * @brief parser for sys_cfg_80211d input
3489 * @param argc Number of arguments
3490 * @param argv Pointer to the arguments
3491 * @param output stores indexes for "state, country"
3498 parse_input_80211d(int argc, char **argv, int output[2][2])
3501 char *keywords[2] = { "state", "country" };
3503 for (i = 0; i < 2; i++)
3506 for (i = 0; i < argc; i++) {
3507 for (j = 0; j < 2; j++) {
3508 if (strcmp(argv[i], keywords[j]) == 0) {
3509 output[j][1] = output[j][0] = i;
3519 * @brief Set/Get 802.11D country information
3521 * Usage: cfg_80211d state country_code
3525 * @param argc Number of arguments
3526 * @param argv Pointer to the arguments
3530 apcmd_cfg_80211d(int argc, char *argv[])
3532 APCMDBUF_CFG_80211D *cmd_buf = NULL;
3533 IEEEtypes_SubbandSet_t *subband = NULL;
3538 int ret = UAP_FAILURE;
3542 char country[4] = { ' ', ' ', 0, 0 };
3543 u8 sflag = 0, cflag = 0;
3544 IEEEtypes_SubbandSet_t sub_bands[MAX_SUB_BANDS];
3545 u8 no_of_sub_band = 0;
3547 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
3550 print_apcmd_cfg_80211d_usage();
3559 parse_input_80211d(argc, argv, output);
3562 if ((output[0][0] != -1) && (output[0][1] > output[0][0])) {
3563 if ((output[0][1] - output[0][0]) != 2) {
3564 printf("ERR: Invalid state inputs\n");
3565 print_apcmd_cfg_80211d_usage();
3569 if (IS_HEX_OR_DIGIT(argv[output[0][0] + 1]) == UAP_FAILURE) {
3570 printf("ERR: valid input for state are 0 or 1\n");
3571 print_apcmd_cfg_80211d_usage();
3574 state = (u8) A2HEXDECIMAL(argv[output[0][0] + 1]);
3576 if ((state != 0) && (state != 1)) {
3577 printf("ERR: valid input for state are 0 or 1 \n");
3578 print_apcmd_cfg_80211d_usage();
3585 if ((output[1][0] != -1) && (output[1][1] > output[1][0])) {
3586 if ((output[1][1] - output[1][0]) > 2) {
3587 printf("ERR: Invalid country inputs\n");
3588 print_apcmd_cfg_80211d_usage();
3591 if ((strlen(argv[output[1][0] + 1]) > 3) ||
3592 (strlen(argv[output[1][0] + 1]) < 0)) {
3593 print_apcmd_cfg_80211d_usage();
3597 strcpy(country, argv[output[1][0] + 1]);
3599 for (i = 0; i < strlen(country); i++) {
3600 if ((country[i] < 'A') || (country[i] > 'z')) {
3601 printf("Invalid Country Code\n");
3602 print_apcmd_cfg_80211d_usage();
3605 if (country[i] > 'Z')
3606 country[i] = country[i] - 'a' + 'A';
3611 /** Get domain information from the file */
3612 no_of_sub_band = parse_domain_file(country, sub_bands);
3613 if (no_of_sub_band == UAP_FAILURE) {
3614 printf("Parsing Failed\n");
3620 if (argc && !cflag && !sflag) {
3621 printf("ERR: Invalid input\n");
3622 print_apcmd_cfg_80211d_usage();
3626 if (sflag && !cflag) {
3628 * Update MIB only and return
3630 if (sg_snmp_mib(ACTION_SET, OID_80211D_ENABLE, sizeof(state), &state) ==
3632 printf("802.11d %sd \n", state ? "enable" : "disable");
3637 buf_len = sizeof(APCMDBUF_CFG_80211D);
3640 buf_len += no_of_sub_band * sizeof(IEEEtypes_SubbandSet_t);
3642 buf_len += MAX_SUB_BANDS * sizeof(IEEEtypes_SubbandSet_t);
3645 buf = (u8 *) malloc(buf_len);
3647 printf("ERR:Cannot allocate buffer from command!\n");
3650 bzero((char *) buf, buf_len);
3651 /* Locate headers */
3652 cmd_buf = (APCMDBUF_CFG_80211D *) buf;
3653 cmd_len = argc ? buf_len :
3655 (sizeof(APCMDBUF_CFG_80211D) - sizeof(domain_param_t)); /** Get */
3657 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
3658 cmd_buf->Result = 0;
3659 cmd_buf->SeqNum = 0;
3660 cmd_buf->Action = argc ? ACTION_SET : ACTION_GET;
3661 cmd_buf->Action = uap_cpu_to_le16(cmd_buf->Action);
3662 cmd_buf->CmdCode = HostCmd_CMD_802_11D_DOMAIN_INFO;
3665 cmd_buf->Domain.Tag = uap_cpu_to_le16(TLV_TYPE_DOMAIN);
3666 cmd_buf->Domain.Length = uap_cpu_to_le16(sizeof(domain_param_t)
3671 (IEEEtypes_SubbandSet_t)));
3673 memset(cmd_buf->Domain.CountryCode, ' ',
3674 sizeof(cmd_buf->Domain.CountryCode));
3675 memcpy(cmd_buf->Domain.CountryCode, country, strlen(country));
3676 memcpy(cmd_buf->Domain.Subband, sub_bands,
3677 no_of_sub_band * sizeof(IEEEtypes_SubbandSet_t));
3680 /* Send the command */
3681 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
3682 if (ret == UAP_SUCCESS) {
3683 if (cmd_buf->Result == CMD_SUCCESS) {
3685 printf("Set executed successfully\n");
3688 (ACTION_SET, OID_80211D_ENABLE, sizeof(state),
3689 &state) == UAP_SUCCESS) {
3690 printf("802.11d %sd \n", state ? "enable" : "disable");
3694 j = uap_le16_to_cpu(cmd_buf->Domain.Length);
3696 (ACTION_GET, OID_80211D_ENABLE, sizeof(state), &state)
3698 printf("State = %sd\n", state ? "enable" : "disable");
3701 if (!(cmd_buf->Domain.CountryCode[0] |
3702 cmd_buf->Domain.CountryCode[1] |
3703 cmd_buf->Domain.CountryCode[2])) {
3704 printf("Dot11d = country code is not set.\n");
3706 printf("Country string = %c%c%c",
3707 cmd_buf->Domain.CountryCode[0],
3708 cmd_buf->Domain.CountryCode[1],
3709 cmd_buf->Domain.CountryCode[2]);
3710 j -= sizeof(cmd_buf->Domain.CountryCode);
3712 (IEEEtypes_SubbandSet_t *) cmd_buf->Domain.Subband;
3713 printf("\nSub-band info=");
3714 // printf("\n\t\t(First Channel, Number of Channels,
3715 // Maximum TX Power) \n");
3716 printf("\t(1st, #chan, MAX-power) \n");
3717 for (i = 0; i < (j / 3); i++) {
3718 printf("\t\t(%d, \t%d, \t%d dbm)\n", subband->FirstChan,
3719 subband->NoOfChan, subband->MaxTxPwr);
3725 printf("ERR:Command Response incorrect!\n");
3728 printf("ERR:Command sending failed!\n");
3735 * @brief Creates a sys_config request and sends to the driver
3737 * Usage: "Usage : sys_config [CONFIG_FILE]"
3739 * @param argc Number of arguments
3740 * @param argv Pointer to the arguments
3741 * @return UAP_SUCCESS or UAP_FAILURE
3744 apcmd_sys_config(int argc, char *argv[])
3746 APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
3750 int ret = UAP_FAILURE;
3755 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
3758 print_sys_config_usage();
3765 /* Check arguments */
3767 printf("ERR:Too many arguments.\n");
3768 print_sys_config_usage();
3772 /* Read profile and send command to firmware */
3773 apcmd_sys_config_profile(argc, argv);
3777 /** Query AP's setting */
3778 buf_len = MRVDRV_SIZE_OF_CMD_BUFFER;
3780 /* alloc buf for command */
3781 buf = (u8 *) malloc(buf_len);
3784 printf("ERR:Cannot allocate buffer from command!\n");
3787 bzero((char *) buf, buf_len);
3789 /* Locate headers */
3790 cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE);
3791 cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buf;
3793 /* Fill the command buffer */
3794 cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
3795 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
3796 cmd_buf->SeqNum = 0;
3797 cmd_buf->Result = 0;
3799 /* Send the command */
3800 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
3802 /* Process response */
3803 if (ret == UAP_SUCCESS) {
3804 /* Verify response */
3805 if (cmd_buf->CmdCode != (APCMD_SYS_CONFIGURE | APCMD_RESP_CHECK)) {
3806 printf("ERR:Corrupted response!\n");
3810 /* Print response */
3811 if (cmd_buf->Result == CMD_SUCCESS) {
3812 printf("AP settings:\n");
3813 print_tlv(buf + sizeof(APCMDBUF_SYS_CONFIGURE),
3814 cmd_buf->Size - sizeof(APCMDBUF_SYS_CONFIGURE) +
3816 printf("\n802.11D setting:\n");
3817 apcmd_cfg_80211d(1, argv_dummy);
3819 printf("ERR:Could not retrieve system configure\n");
3822 printf("ERR:Command sending failed!\n");
3825 memset(&pm, 0, sizeof(ps_mgmt));
3826 send_power_mode_ioctl(&pm);
3831 * @brief Send read/write command along with register details to the driver
3832 * @param reg reg type
3833 * @param offset pointer to register offset string
3834 * @param strvalue pointer to value string
3835 * @return UAP_SUCCESS or UAP_FAILURE
3838 apcmd_regrdwr_process(int reg, s8 * offset, s8 * strvalue)
3840 APCMDBUF_REG_RDWR *cmd_buf = NULL;
3844 int ret = UAP_FAILURE;
3847 buf_len = sizeof(APCMDBUF_REG_RDWR);
3849 /* alloc buf for command */
3850 buf = (u8 *) malloc(buf_len);
3853 printf("ERR:Cannot allocate buffer from command!\n");
3856 bzero((char *) buf, buf_len);
3858 /* Locate headers */
3859 cmd_len = sizeof(APCMDBUF_REG_RDWR);
3860 cmd_buf = (APCMDBUF_REG_RDWR *) buf;
3862 /* Fill the command buffer */
3863 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
3864 cmd_buf->SeqNum = 0;
3865 cmd_buf->Result = 0;
3870 cmd_buf->CmdCode = HostCmd_CMD_MAC_REG_ACCESS;
3874 cmd_buf->CmdCode = HostCmd_CMD_BBP_REG_ACCESS;
3877 cmd_buf->CmdCode = HostCmd_CMD_RF_REG_ACCESS;
3881 printf("Invalid register set specified.\n");
3886 cmd_buf->Action = 1; // WRITE
3888 cmd_buf->Action = 0; // READ
3890 cmd_buf->Action = uap_cpu_to_le16(cmd_buf->Action);
3891 cmd_buf->Offset = A2HEXDECIMAL(offset);
3892 cmd_buf->Offset = uap_cpu_to_le16(cmd_buf->Offset);
3894 cmd_buf->Value = A2HEXDECIMAL(strvalue);
3895 cmd_buf->Value = uap_cpu_to_le32(cmd_buf->Value);
3898 /* Send the command */
3899 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
3901 /* Process response */
3902 if (ret == UAP_SUCCESS) {
3903 if (cmd_buf->Result == CMD_SUCCESS) {
3904 printf("Successfully executed the command\n");
3905 printf("%s[0x%04hx] = 0x%08lx\n",
3906 whichreg, uap_le16_to_cpu(cmd_buf->Offset),
3907 uap_le32_to_cpu(cmd_buf->Value));
3909 printf("ERR:Command sending failed!\n");
3914 printf("ERR:Command sending failed!\n");
3924 * @brief Send read command for EEPROM
3926 * Usage: "Usage : rdeeprom <offset> <byteCount>"
3928 * @param argc Number of arguments
3929 * @param argv Pointer to the arguments
3933 apcmd_read_eeprom(int argc, char *argv[])
3935 APCMDBUF_EEPROM_ACCESS *cmd_buf = NULL;
3939 u16 byteCount, offset;
3940 int ret = UAP_FAILURE;
3942 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
3945 print_apcmd_read_eeprom_usage();
3952 /* Check arguments */
3953 if (!argc || (argc && is_input_valid(RDEEPROM, argc, argv) != UAP_SUCCESS)) {
3954 print_apcmd_read_eeprom_usage();
3957 offset = A2HEXDECIMAL(argv[0]);
3958 byteCount = A2HEXDECIMAL(argv[1]);
3960 buf_len = sizeof(APCMDBUF_EEPROM_ACCESS) + MAX_EEPROM_LEN;
3961 buf = (u8 *) malloc(buf_len);
3963 printf("ERR:Cannot allocate buffer from command!\n");
3966 bzero((char *) buf, buf_len);
3968 /* Locate headers */
3969 cmd_buf = (APCMDBUF_EEPROM_ACCESS *) buf;
3970 cmd_len = sizeof(APCMDBUF_EEPROM_ACCESS);
3972 cmd_buf->Size = sizeof(APCMDBUF_EEPROM_ACCESS) - BUF_HEADER_SIZE;
3973 cmd_buf->Result = 0;
3974 cmd_buf->SeqNum = 0;
3975 cmd_buf->Action = 0;
3977 cmd_buf->CmdCode = HostCmd_EEPROM_ACCESS;
3978 cmd_buf->Offset = uap_cpu_to_le16(offset);
3979 cmd_buf->ByteCount = uap_cpu_to_le16(byteCount);
3981 /* Send the command */
3982 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
3984 /* Process response */
3985 if (ret == UAP_SUCCESS) {
3986 if (cmd_buf->Result == CMD_SUCCESS) {
3987 printf("Successfully executed the command\n");
3988 byteCount = uap_le16_to_cpu(cmd_buf->ByteCount);
3989 offset = uap_le16_to_cpu(cmd_buf->Offset);
3990 hexdump_data("EEPROM", (void *) cmd_buf->Value, byteCount, ' ');
3992 printf("ERR:Command Response incorrect!\n");
3995 printf("ERR:Command sending failed!\n");
4003 * @brief Show usage information for the regrdwr command
4009 print_regrdwr_usage(void)
4011 printf("\nUsage : uaputl.exe regrdwr <TYPE> <OFFSET> [value]\n");
4012 printf("\nTYPE Options: 0 - read/write MAC register");
4013 printf("\n 1 - read/write BBP register");
4014 printf("\n 2 - read/write RF register");
4021 * @brief Provides interface to perform read/write operations on regsiters
4022 * @param argc Number of arguments
4023 * @param argv Pointer to the arguments
4027 apcmd_regrdwr(int argc, char *argv[])
4031 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
4034 print_regrdwr_usage();
4041 /* Check arguments */
4042 if ((argc < 2) || (argc > 3)) {
4043 printf("ERR:wrong arguments.\n");
4044 print_regrdwr_usage();
4047 if ((atoi(argv[0]) != 0) && (atoi(argv[0]) != 1) && (atoi(argv[0]) != 2)) {
4048 printf("ERR:Illegal register type %s. Must be either '0','1' or '2'.\n",
4050 print_regrdwr_usage();
4053 reg = atoi(argv[0]);
4054 apcmd_regrdwr_process(reg, argv[1], argc > 2 ? argv[2] : NULL);
4059 * @brief Show usage information for the memaccess command
4065 print_memaccess_usage(void)
4067 printf("\nUsage : uaputl.exe memaccess <ADDRESS> [value]\n");
4068 printf("\nRead/Write memory location");
4069 printf("\nADDRESS: Address of the memory location to be read/written");
4070 printf("\nValue : Value to be written at that address\n");
4075 * @brief Provides interface to perform read/write memory location
4076 * @param argc Number of arguments
4077 * @param argv Pointer to the arguments
4081 apcmd_memaccess(int argc, char *argv[])
4084 APCMDBUF_MEM_ACCESS *cmd_buf = NULL;
4088 int ret = UAP_FAILURE;
4092 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
4095 print_memaccess_usage();
4102 /* Check arguments */
4103 if ((argc < 1) || (argc > 2)) {
4104 printf("ERR:wrong arguments.\n");
4105 print_memaccess_usage();
4113 buf_len = sizeof(APCMDBUF_MEM_ACCESS);
4115 /* alloc buf for command */
4116 buf = (u8 *) malloc(buf_len);
4119 printf("ERR:Cannot allocate buffer from command!\n");
4122 bzero((char *) buf, buf_len);
4123 /* Locate headers */
4124 cmd_len = sizeof(APCMDBUF_MEM_ACCESS);
4125 cmd_buf = (APCMDBUF_MEM_ACCESS *) buf;
4127 /* Fill the command buffer */
4128 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
4129 cmd_buf->SeqNum = 0;
4130 cmd_buf->Result = 0;
4131 cmd_buf->CmdCode = HostCmd_CMD_MEM_ACCESS;
4134 cmd_buf->Action = 1; // WRITE
4136 cmd_buf->Action = 0; // READ
4138 cmd_buf->Action = uap_cpu_to_le16(cmd_buf->Action);
4139 cmd_buf->Address = A2HEXDECIMAL(address);
4140 cmd_buf->Address = uap_cpu_to_le32(cmd_buf->Address);
4143 cmd_buf->Value = A2HEXDECIMAL(value);
4144 cmd_buf->Value = uap_cpu_to_le32(cmd_buf->Value);
4147 /* Send the command */
4148 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
4150 /* Process response */
4151 if (ret == UAP_SUCCESS) {
4152 if (cmd_buf->Result == CMD_SUCCESS) {
4153 printf("Successfully executed the command\n");
4154 printf("[0x%04lx] = 0x%08lx\n",
4155 uap_le32_to_cpu(cmd_buf->Address),
4156 uap_le32_to_cpu(cmd_buf->Value));
4158 printf("ERR:Command sending failed!\n");
4163 printf("ERR:Command sending failed!\n");
4172 * @brief Show usage information for sys_debug command
4178 print_sys_debug_usage(void)
4180 printf("\nUsage : uaputl.exe sys_debug <subcmd> [parameter]\n");
4181 printf("\nSet/Get debug parameter");
4182 printf("\nsubcmd: used to set/get debug parameters or set user scan");
4183 printf("\nparameter : parameters for specific subcmd");
4184 printf("\n If no [parameter] are given, it return");
4185 printf("\n debug parameters for selected subcmd");
4191 * @brief Creates a sys_debug request and sends to the driver
4192 * @param argc Number of arguments
4193 * @param argv Pointer to the arguments
4197 apcmd_sys_debug(int argc, char *argv[])
4199 APCMDBUF_SYS_DEBUG *cmd_buf = NULL;
4204 int ret = UAP_FAILURE;
4208 while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
4211 print_sys_debug_usage();
4217 /* Check arguments */
4218 if ((argc == 0) || (argc > 2)) {
4219 printf("ERR:wrong arguments.\n");
4220 print_sys_debug_usage();
4225 parameter = A2HEXDECIMAL(value);
4228 subcmd = atoi(argv[0]);
4229 /* Initialize the command length */
4230 if (subcmd == DEBUG_SUBCOMMAND_CHANNEL_SCAN) {
4232 sizeof(APCMDBUF_SYS_DEBUG) +
4233 MAX_CHANNELS * sizeof(CHANNEL_SCAN_ENTRY_T);
4234 cmd_len = sizeof(APCMDBUF_SYS_DEBUG) - sizeof(debugConfig_t);
4236 cmd_len = sizeof(APCMDBUF_SYS_DEBUG);
4240 /* Initialize the command buffer */
4241 buffer = (u8 *) malloc(buf_len);
4243 printf("ERR:Cannot allocate buffer for command!\n");
4246 bzero((char *) buffer, buf_len);
4248 /* Locate headers */
4249 cmd_buf = (APCMDBUF_SYS_DEBUG *) buffer;
4251 /* Fill the command buffer */
4252 cmd_buf->CmdCode = APCMD_SYS_DEBUG;
4253 cmd_buf->Size = cmd_len - BUF_HEADER_SIZE;
4254 cmd_buf->SeqNum = 0;
4255 cmd_buf->Result = 0;
4256 cmd_buf->subcmd = subcmd;
4257 if (subcmd == DEBUG_SUBCOMMAND_CHANNEL_SCAN) {
4258 cmd_buf->Action = ACTION_SET;
4261 cmd_buf->Action = ACTION_GET;
4263 cmd_buf->Action = ACTION_SET;
4264 if (subcmd == DEBUG_SUBCOMMAND_GMODE)
4265 cmd_buf->debugConfig.globalDebugMode = (u8) parameter;
4266 else if (subcmd == DEBUG_SUBCOMMAND_MAJOREVTMASK) {
4267 cmd_buf->debugConfig.debugMajorIdMask = parameter;
4268 cmd_buf->debugConfig.debugMajorIdMask =
4269 uap_cpu_to_le32(cmd_buf->debugConfig.debugMajorIdMask);
4271 cmd_buf->debugConfig.value = uap_cpu_to_le32(parameter);
4275 cmd_buf->Action = uap_cpu_to_le16(cmd_buf->Action);
4276 cmd_buf->subcmd = uap_cpu_to_le32(cmd_buf->subcmd);
4278 /* Send the command */
4279 ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, buf_len);
4281 /* Process response */
4282 if (ret == UAP_SUCCESS) {
4283 /* Verify response */
4284 if (cmd_buf->CmdCode != (APCMD_SYS_DEBUG | APCMD_RESP_CHECK)) {
4285 printf("ERR:Corrupted response! CmdCode=%x\n", cmd_buf->CmdCode);
4289 /* Print response */
4290 if (cmd_buf->Result == CMD_SUCCESS) {
4291 if (subcmd == DEBUG_SUBCOMMAND_CHANNEL_SCAN) {
4293 CHANNEL_SCAN_ENTRY_T *cst = NULL;
4295 (sizeof(APCMDBUF_SYS_DEBUG) - BUF_HEADER_SIZE)) {
4297 ("ERR: Invalid command response size, cmd_buf->Size = %x\n",
4302 for (i = 0; i < cmd_buf->debugConfig.cs_entry.numChannels; i++) {
4305 ("\n------------------------------------------------------");
4306 printf("\nChan\tNumAPs\tCCA_Count\tDuration\tWeight");
4308 ("\n------------------------------------------------------");
4309 cst = cmd_buf->debugConfig.cs_entry.cst;
4311 printf("\n%d\t%d\t%ld\t\t%ld\t\t%ld", cst->chan_num,
4313 cst->CCA_count, cst->duration, cst->channel_weight);
4317 ("\n------------------------------------------------------\n");
4320 if (subcmd == DEBUG_SUBCOMMAND_GMODE) {
4321 printf("globalDebugmode=%d\n",
4322 cmd_buf->debugConfig.globalDebugMode);
4323 } else if (subcmd == DEBUG_SUBCOMMAND_MAJOREVTMASK) {
4324 printf("MajorId mask=0x%08lx\n",
4325 uap_le32_to_cpu(cmd_buf->debugConfig.
4328 printf("Value = %ld\n",
4329 uap_le32_to_cpu(cmd_buf->debugConfig.value));
4332 printf("set debug parameter successful\n");
4337 printf("ERR:Could not get debug parameter!\n");
4339 printf("ERR:Could not set debug parameter!\n");
4343 printf("ERR:Command sending failed!\n");
4350 /** structure of command table*/
4355 /** command function pointer */
4356 void (*func) (int argc, char *argv[]);
4357 /**command usuage */
4361 /** ap command table */
4362 static command_table ap_command[] = {
4363 {"sys_config", apcmd_sys_config, "\tSet/get uAP's profile"},
4364 {"sys_info", apcmd_sys_info, "\tDisplay system info"},
4365 {"sys_reset", apcmd_sys_reset, "\tReset uAP"},
4366 {"bss_start", apcmd_bss_start, "\tStart the BSS"},
4367 {"bss_stop", apcmd_bss_stop, "\tStop the BSS"},
4368 {"sta_deauth", apcmd_sta_deauth, "\tDeauth client"},
4369 {"sta_list", apcmd_sta_list, "\tDisplay list of clients"},
4370 {"sys_cfg_ap_mac_address", apcmd_sys_cfg_ap_mac_address,
4371 "Set/get uAP mac address"},
4372 {"sys_cfg_ssid", apcmd_sys_cfg_ssid, "\tSet/get uAP ssid"},
4373 {"sys_cfg_beacon_period", apcmd_sys_cfg_beacon_period,
4374 "Set/get uAP beacon period"},
4375 {"sys_cfg_dtim_period", apcmd_sys_cfg_dtim_period,
4376 "Set/get uAP dtim period"},
4377 {"sys_cfg_channel", apcmd_sys_cfg_channel, "\tSet/get uAP radio channel"},
4378 {"sys_cfg_scan_channels", apcmd_sys_cfg_scan_channels,
4379 "Set/get uAP radio channel list"},
4380 {"sys_cfg_rates", apcmd_sys_cfg_rates, "\tSet/get uAP rates"},
4381 {"sys_cfg_rates_ext", apcmd_sys_cfg_rates_ext,
4382 "Set/get uAP rates (extended)"},
4383 {"sys_cfg_tx_power", apcmd_sys_cfg_tx_power, "Set/get uAP tx power"},
4384 {"sys_cfg_bcast_ssid_ctl", apcmd_sys_cfg_bcast_ssid_ctl,
4385 "Set/get uAP broadcast ssid"},
4386 {"sys_cfg_preamble_ctl", apcmd_sys_cfg_preamble_ctl, "Get uAP preamble"},
4387 {"sys_cfg_antenna_ctl", apcmd_sys_cfg_antenna_ctl,
4388 "Set/get uAP tx/rx antenna"},
4389 {"sys_cfg_rts_threshold", apcmd_sys_cfg_rts_threshold,
4390 "Set/get uAP rts threshold"},
4391 {"sys_cfg_frag_threshold", apcmd_sys_cfg_frag_threshold,
4392 "Set/get uAP frag threshold"},
4393 {"sys_cfg_radio_ctl", apcmd_sys_cfg_radio_ctl, "Set/get uAP radio on/off"},
4394 {"sys_cfg_tx_data_rate", apcmd_sys_cfg_tx_data_rate, "Set/get uAP tx rate"},
4395 {"sys_cfg_mcbc_data_rate", apcmd_sys_cfg_mcbc_data_rate,
4396 "Set/get uAP MCBC rate"},
4397 {"sys_cfg_rsn_replay_prot", apcmd_sys_cfg_rsn_replay_prot,
4398 "Set/get RSN replay protection"},
4399 {"sys_cfg_pkt_fwd_ctl", apcmd_sys_cfg_pkt_fwd_ctl,
4400 "Set/get uAP packet forwarding"},
4401 {"sys_cfg_sta_ageout_timer", apcmd_sys_cfg_sta_ageout_timer,
4402 "Set/get station ageout timer"},
4403 {"sys_cfg_auth", apcmd_sys_cfg_auth, "\tSet/get uAP authentication mode"},
4404 {"sys_cfg_protocol", apcmd_sys_cfg_protocol,
4405 "Set/get uAP security protocol"},
4406 {"sys_cfg_wep_key", apcmd_sys_cfg_wep_key, "\tSet/get uAP wep key"},
4407 {"sys_cfg_cipher", apcmd_sys_cfg_cipher, "\tSet/get uAP WPA/WPA cipher"},
4408 {"sys_cfg_wpa_passphrase", apcmd_sys_cfg_wpa_passphrase,
4409 "Set/get uAP WPA or WPA2 passphrase"},
4410 {"sys_cfg_group_rekey_timer", apcmd_sys_cfg_group_rekey_timer,
4411 "Set/get uAP group re-key time"},
4412 {"sys_cfg_max_sta_num", apcmd_sys_cfg_max_sta_num,
4413 "Set/get uAP max station number"},
4414 {"sys_cfg_retry_limit", apcmd_sys_cfg_retry_limit,
4415 "Set/get uAP retry limit number"},
4416 {"sys_cfg_custom_ie", apcmd_sys_cfg_custom_ie,
4417 "\tSet/get custom IE configuration"},
4418 {"sta_filter_table", apcmd_sta_filter_table, "Set/get uAP mac filter"},
4419 {"regrdwr", apcmd_regrdwr, "\t\tRead/Write register command"},
4420 {"memaccess", apcmd_memaccess, "\tRead/Write to a memory address command"},
4421 {"rdeeprom", apcmd_read_eeprom, "\tRead EEPROM "},
4422 {"cfg_data", apcmd_cfg_data,
4423 "\tGet/Set configuration file from/to firmware"},
4424 {"sys_debug", apcmd_sys_debug, "\tSet/Get debug parameter"},
4425 {"sys_cfg_80211d", apcmd_cfg_80211d, "\tSet/Get 802.11D info"},
4426 {"uap_stats", apcmd_uap_stats, "\tGet uAP stats"},
4427 {"powermode", apcmd_power_mode, "\tSet/get uAP power mode"},
4428 {"coex_config", apcmd_coex_config, "\tSet/get uAP BT coex configuration"},
4433 * @brief Prints usage information of uaputl
4438 print_tool_usage(void)
4441 printf("uaputl.exe - uAP utility ver %s\n", UAP_VERSION);
4443 "\tuaputl.exe [options] <command> [command parameters]\n");
4445 "\t--help\tDisplay help\n"
4446 "\t-v\tDisplay version\n"
4447 "\t-i <interface>\n" "\t-d <debug_level=0|1|2>\n");
4448 printf("Commands:\n");
4449 for (i = 0; ap_command[i].cmd; i++)
4450 printf("\t%-4s\t\t%s\n", ap_command[i].cmd, ap_command[i].help);
4452 "For more information on the usage of each command use:\n"
4453 "\tuaputl.exe <command> --help\n");
4456 /****************************************************************************
4458 ****************************************************************************/
4459 /** option parameter*/
4460 static struct option ap_options[] = {
4461 {"help", 0, NULL, 'h'},
4462 {"interface", 1, NULL, 'i'},
4463 {"debug", 1, NULL, 'd'},
4464 {"version", 0, NULL, 'v'},
4465 {NULL, 0, NULL, '\0'}
4469 * @brief isdigit for String.
4471 * @param x char string
4472 * @return UAP_FAILURE for non-digit.
4473 * UAP_SUCCESS for digit
4479 for (i = 0; i < strlen(x); i++)
4480 if (isdigit(x[i]) == 0)
4486 * @brief Checkes a particular input for validatation.
4488 * @param cmd Type of input
4489 * @param argc Number of arguments
4490 * @param argv Pointer to the arguments
4491 * @return UAP_SUCCESS or UAP_FAILURE
4494 is_input_valid(valid_inputs cmd, int argc, char *argv[])
4497 int ret = UAP_SUCCESS;
4503 printf(" ERR: Argument count mismatch\n");
4506 if ((ISDIGIT(argv[0]) == 0) || (ISDIGIT(argv[1]) == 0) ||
4507 (A2HEXDECIMAL(argv[0]) & 0x03) ||
4508 (A2HEXDECIMAL(argv[0]) < 0) ||
4509 (A2HEXDECIMAL(argv[1]) & 0x03) ||
4510 (A2HEXDECIMAL(argv[1]) < 4) || (A2HEXDECIMAL(argv[1]) > 20)) {
4511 printf(" ERR: Invalid inputs for Read EEPROM\n");
4517 if (argc > MAX_CHANNELS) {
4518 printf("ERR: Invalid List of Channels\n");
4521 for (i = 0; i < argc; i++) {
4522 if ((ISDIGIT(argv[i]) == 0) || (atoi(argv[i]) < 1) ||
4523 (atoi(argv[i]) > MAX_CHANNELS)) {
4524 printf("ERR: Channel must be in the range of 1 to %d\n",
4530 if ((ret != UAP_FAILURE) &&
4531 (has_dup_channel(argc, argv) != UAP_SUCCESS)) {
4532 printf("ERR: Duplicate channel values entered\n");
4538 if ((argc > 1) || (ISDIGIT(argv[0]) == 0)) {
4539 printf("ERR:Invalid Transmit power\n");
4542 if ((atoi(argv[0]) < MIN_TX_POWER) ||
4543 (atoi(argv[0]) > MAX_TX_POWER)) {
4544 printf("ERR: TX Powar must be in the rage of %d to %d. \n",
4545 MIN_TX_POWER, MAX_TX_POWER);
4551 if ((argc > 1) || (ISDIGIT(argv[0]) == 0)) {
4552 printf("ERR:Invalid Protocol\n");
4555 ret = is_protocol_valid(atoi(argv[0]));
4558 if ((argc != 1) && (argc != 2)) {
4559 printf("ERR: Incorrect arguments for channel.\n");
4563 if ((ISDIGIT(argv[1]) == 0) || (atoi(argv[1]) < 0) ||
4564 (atoi(argv[1]) > 1)) {
4565 printf("ERR: MODE must be either 0 or 1\n");
4568 if ((atoi(argv[1]) == 1) && (atoi(argv[0]) != 0)) {
4569 printf("ERR: Channel must be 0 for ACS; MODE = 1.\n");
4573 if ((argc == 1) || (atoi(argv[1]) == 0)) {
4574 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 1) ||
4575 (atoi(argv[0]) > MAX_CHANNELS)) {
4576 printf("ERR: Channel must be in the range of 1 to %d\n",
4584 if (argc > MAX_RATES) {
4585 printf("ERR: Incorrect number of RATES arguments.\n");
4588 for (i = 0; i < argc; i++) {
4589 if ((IS_HEX_OR_DIGIT(argv[i]) == UAP_FAILURE) ||
4590 (is_rate_valid(A2HEXDECIMAL(argv[i]) & ~BASIC_RATE_SET_BIT)
4592 printf("ERR:Unsupported rate.\n");
4597 if ((ret != UAP_FAILURE) &&
4598 (has_dup_rate(argc, argv) != UAP_SUCCESS)) {
4599 printf("ERR: Duplicate rate values entered\n");
4602 if (check_mandatory_rates(argc, argv) != UAP_SUCCESS) {
4609 printf("ERR:wrong BROADCASTSSID arguments.\n");
4612 if ((ISDIGIT(argv[0]) == 0) ||
4613 ((atoi(argv[0]) != 0) && (atoi(argv[0]) != 1))) {
4615 ("ERR:Illegal parameter %s for BROADCASTSSID. Must be either '0' or '1'.\n",
4623 printf("ERR:Incorrect number of arguments for RTSTHRESHOLD\n");
4625 } else if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4626 (atoi(argv[0]) > MAX_RTS_THRESHOLD)) {
4628 ("ERR:Illegal RTSTHRESHOLD %s. The value must between 0 and %d\n",
4629 argv[0], MAX_RTS_THRESHOLD);
4635 printf("ERR:Incorrect number of arguments for FRAGTHRESH\n");
4637 } else if ((ISDIGIT(argv[0]) == 0) ||
4638 (atoi(argv[0]) < MIN_FRAG_THRESHOLD) ||
4639 (atoi(argv[0]) > MAX_FRAG_THRESHOLD)) {
4641 ("ERR:Illegal FRAGTHRESH %s. The value must between %d and %d\n",
4642 argv[0], MIN_FRAG_THRESHOLD, MAX_FRAG_THRESHOLD);
4648 printf("ERR:Incorrect number of arguments for DTIMPERIOD\n");
4650 } else if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 1) ||
4651 (atoi(argv[0]) > MAX_DTIM_PERIOD)) {
4652 printf("ERR: DTIMPERIOD Value must be in range of 1 to %d\n",
4659 printf("ERR:Incorrect number of arguments for RADIOCONTROL\n");
4662 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4663 (atoi(argv[0]) > 1)) {
4665 ("ERR:Illegal RADIOCONTROL parameter %s. Must be either '0' or '1'.\n",
4673 printf("ERR:wrong RSNREPLAYPROT arguments.\n");
4676 if ((ISDIGIT(argv[0]) == 0) ||
4677 ((atoi(argv[0]) != 0) && (atoi(argv[0]) != 1))) {
4679 ("ERR:Illegal parameter %s for RSNREPLAYPROT. Must be either '0' or '1'.\n",
4688 printf("ERR:Incorrect number of arguments for DATARATE\n");
4691 if (IS_HEX_OR_DIGIT(argv[0]) == UAP_FAILURE) {
4692 printf("ERR: invalid data rate\n");
4694 } else if ((A2HEXDECIMAL(argv[0]) != 0) &&
4696 (A2HEXDECIMAL(argv[0]) & ~BASIC_RATE_SET_BIT) !=
4698 printf("ERR: invalid data rate\n");
4705 printf("ERR:Incorrect number of arguments for PKTFWD.\n");
4707 } else if ((ISDIGIT(argv[0]) == 0) ||
4708 ((atoi(argv[0]) != 0) && (atoi(argv[0]) != 1))) {
4710 ("ERR:Illegal PKTFWD parameter %s. Must be either '0' or '1'.\n",
4715 case STAAGEOUTTIMER:
4717 printf("ERR:Incorrect number of arguments for STAAGEOUTTIMER.\n");
4720 if ((ISDIGIT(argv[0]) == 0) || ((atoi(argv[0]) != 0) &&
4722 MIN_STAGE_OUT_TIME) ||
4724 MAX_STAGE_OUT_TIME)))) {
4726 ("ERR:Illegal STAAGEOUTTIMER %s. Must be between %d and %d.\n",
4727 argv[0], MIN_STAGE_OUT_TIME, MAX_STAGE_OUT_TIME);
4734 printf("ERR:Incorrect number of arguments for AUTHMODE\n");
4737 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4738 (atoi(argv[0]) > 1)) {
4740 ("ERR:Illegal AUTHMODE parameter %s. Must be either '0', or '1'.\n",
4746 case GROUPREKEYTIMER:
4748 printf("ERR:Incorrect number of arguments for GROUPREKEYTIMER.\n");
4751 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4752 (atoi(argv[0]) > MAX_GRP_TIMER)) {
4753 printf("ERR: GROUPREKEYTIMER range is [0:%d] (0 for disable)\n",
4761 printf("ERR:Incorrect number of arguments for MAXSTANUM\n");
4764 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) > 8) ||
4765 (atoi(argv[0]) < 0)) {
4766 printf("ERR:STA_NUM must be in the range of [0:8] %s.\n",
4774 printf("ERR:Incorrect number of argument for BEACONPERIOD.\n");
4777 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < MIN_BEACON_PERIOD)
4778 || (atoi(argv[0]) > MAX_BEACON_PERIOD)) {
4779 printf("ERR: BEACONPERIOD must be in range of %d to %d.\n",
4780 MIN_BEACON_PERIOD, MAX_BEACON_PERIOD);
4787 printf("ERR:Incorrect number of arguments for RETRY LIMIT\n");
4790 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) > MAX_RETRY_LIMIT) ||
4791 (atoi(argv[0]) < 0)) {
4793 ("ERR:RETRY_LIMIT must be in the range of [0:%d]. The input was %s.\n",
4794 MAX_RETRY_LIMIT, argv[0]);
4799 case COEX_COMM_BITMAP:
4801 printf("ERR:Incorrect number of arguments for Bitmap.\n");
4804 /* Only bit 0 is supported now, hence check for 1 or 0 */
4805 if ((IS_HEX_OR_DIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4806 (atoi(argv[0]) > 1)) {
4807 printf("ERR: Bitmap must have value of 1 or 0.\n");
4812 case COEX_SCO_ACL_FREQ:
4814 printf("ERR:Incorrect number of arguments for aclFrequency.\n");
4817 if (ISDIGIT(argv[0]) == 0) {
4818 printf("ERR: Incorrect value for aclFrequency.\n");
4823 case COEX_ACL_ENABLED:
4825 printf("ERR:Incorrect number of arguments for (acl) enabled.\n");
4828 if ((ISDIGIT(argv[0]) == 0) || (atoi(argv[0]) < 0) ||
4829 (atoi(argv[0]) > 1)) {
4830 printf("ERR: (acl) enabled must have value of 1 or 0.\n");
4835 case COEX_ACL_BT_TIME:
4836 case COEX_ACL_WLAN_TIME:
4838 printf("ERR:Incorrect number of arguments for bt/wlan time.\n");
4841 if (ISDIGIT(argv[0]) == 0) {
4842 printf("ERR: Incorrect value for bt/wlan time.\n");
4847 case COEX_PROTECTION:
4849 printf("ERR:Incorrect number of arguments for %s.\n", argv[0]);
4852 if (ISDIGIT(argv[1]) == 0) {
4853 printf("ERR: Incorrect value for %s.\n", argv[0]);
4866 * @brief Converts colon separated MAC address to hex value
4868 * @param mac A pointer to the colon separated MAC string
4869 * @param raw A pointer to the hex data buffer
4870 * @return UAP_SUCCESS or UAP_FAILURE
4871 * UAP_RET_MAC_BROADCAST - if broadcast mac
4872 * UAP_RET_MAC_MULTICAST - if multicast mac
4875 mac2raw(char *mac, u8 * raw)
4877 unsigned int temp_raw[ETH_ALEN];
4880 if (strlen(mac) != ((2 * ETH_ALEN) + (ETH_ALEN - 1))) {
4883 num_tokens = sscanf(mac, "%2x:%2x:%2x:%2x:%2x:%2x",
4884 temp_raw + 0, temp_raw + 1, temp_raw + 2, temp_raw + 3,
4885 temp_raw + 4, temp_raw + 5);
4886 if (num_tokens != ETH_ALEN) {
4889 for (i = 0; i < num_tokens; i++)
4890 raw[i] = (u8) temp_raw[i];
4892 if (memcmp(raw, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0) {
4893 return UAP_RET_MAC_BROADCAST;
4894 } else if (raw[0] & 0x01) {
4895 return UAP_RET_MAC_MULTICAST;
4901 * @brief Converts a string to hex value
4903 * @param str A pointer to the string
4904 * @param raw A pointer to the raw data buffer
4905 * @return Number of bytes read
4908 string2raw(char *str, unsigned char *raw)
4910 int len = (strlen(str) + 1) / 2;
4913 if (!isxdigit(*str)) {
4916 *str = toupper(*str);
4917 *raw = CHAR2INT(*str) << 4;
4919 *str = toupper(*str);
4922 *raw |= CHAR2INT(*str);
4924 } while (*++str != '\0');
4929 * @brief Prints a MAC address in colon separated form from hex data
4931 * @param raw A pointer to the hex data buffer
4937 printf("%02x:%02x:%02x:%02x:%02x:%02x", (unsigned int) raw[0],
4938 (unsigned int) raw[1], (unsigned int) raw[2], (unsigned int) raw[3],
4939 (unsigned int) raw[4], (unsigned int) raw[5]);
4944 * @brief check hex string
4946 * @param hex A pointer to hex string
4947 * @return UAP_SUCCESS or UAP_FAILURE
4950 ishexstring(void *hex)
4954 int len = strlen(p);
4955 if (!strncasecmp("0x", p, 2)) {
4959 for (i = 0; i < len; i++) {
4969 * @brief Show auth tlv
4971 * @param tlv Poniter to auth tlv
4976 print_auth(TLVBUF_AUTH_MODE * tlv)
4978 switch (tlv->AuthMode) {
4980 printf("AUTHMODE = Open authentication\n");
4983 printf("AUTHMODE = Shared key authentication\n");
4986 printf("AUTHMODE = Auto (open and shared key)\n");
4989 printf("ERR: Invalid authmode=%d\n", tlv->AuthMode);
4996 * @brief Show cipher tlv
4998 * @param tlv Poniter to cipher tlv
5003 print_cipher(TLVBUF_CIPHER * tlv)
5005 switch (tlv->PairwiseCipher) {
5007 printf("PairwiseCipher = TKIP\n");
5009 case CIPHER_AES_CCMP:
5010 printf("PairwiseCipher = AES CCMP\n");
5012 case CIPHER_TKIP | CIPHER_AES_CCMP:
5013 printf("PairwiseCipher = TKIP + AES CCMP\n");
5016 printf("PairwiseCipher = None\n");
5019 printf("Unknown Pairwise cipher 0x%x\n", tlv->PairwiseCipher);
5022 switch (tlv->GroupCipher) {
5024 printf("GroupCipher = TKIP\n");
5026 case CIPHER_AES_CCMP:
5027 printf("GroupCipher = AES CCMP\n");
5030 printf("GroupCipher = None\n");
5033 printf("Unknown Group cipher 0x%x\n", tlv->GroupCipher);
5039 * @brief Show mac filter tlv
5041 * @param tlv Poniter to filter tlv
5046 print_mac_filter(TLVBUF_STA_MAC_ADDR_FILTER * tlv)
5049 switch (tlv->FilterMode) {
5051 printf("Filter Mode = Filter table is disabled\n");
5055 ("Filter Mode = Allow mac address specified in the allwed list\n");
5059 ("Filter Mode = Block MAC addresses specified in the banned list\n");
5062 for (i = 0; i < tlv->Count; i++) {
5063 printf("MAC_%d = ", i);
5064 print_mac(&tlv->MacAddress[i * ETH_ALEN]);
5070 * @brief Show rate tlv
5072 * @param tlv Poniter to rate tlv
5077 print_rate(TLVBUF_RATES * tlv)
5081 printf("Basic Rates =");
5082 for (i = 0; i < tlv->Length; i++) {
5083 if (tlv->OperationalRates[i] > (BASIC_RATE_SET_BIT - 1)) {
5085 printf(" 0x%x", tlv->OperationalRates[i]);
5088 printf("%s\nNon-Basic Rates =", flag ? "" : " ( none ) ");
5089 for (flag = 0, i = 0; i < tlv->Length; i++) {
5090 if (tlv->OperationalRates[i] < BASIC_RATE_SET_BIT) {
5092 printf(" 0x%x", tlv->OperationalRates[i]);
5095 printf("%s\n", flag ? "" : " ( none ) ");
5099 * @brief Show all the tlv in the buf
5101 * @param buf Poniter to tlv buffer
5102 * @param len tlv buffer len
5107 print_tlv(u8 * buf, u16 len)
5109 TLVBUF_HEADER *pCurrentTlv = (TLVBUF_HEADER *) buf;
5110 int tlvBufLeft = len;
5116 TLVBUF_AP_MAC_ADDRESS *mac_tlv;
5117 TLVBUF_SSID *ssid_tlv;
5118 TLVBUF_BEACON_PERIOD *beacon_tlv;
5119 TLVBUF_DTIM_PERIOD *dtim_tlv;
5120 TLVBUF_RATES *rates_tlv;
5121 TLVBUF_TX_POWER *txpower_tlv;
5122 TLVBUF_BCAST_SSID_CTL *bcast_tlv;
5123 TLVBUF_PREAMBLE_CTL *preamble_tlv;
5124 TLVBUF_ANTENNA_CTL *antenna_tlv;
5125 TLVBUF_RTS_THRESHOLD *rts_tlv;
5126 TLVBUF_RADIO_CTL *radio_tlv;
5127 TLVBUF_TX_DATA_RATE *txrate_tlv;
5128 TLVBUF_MCBC_DATA_RATE *mcbcrate_tlv;
5129 TLVBUF_PKT_FWD_CTL *pkt_fwd_tlv;
5130 TLVBUF_STA_AGEOUT_TIMER *ageout_tlv;
5131 TLVBUF_AUTH_MODE *auth_tlv;
5132 TLVBUF_PROTOCOL *proto_tlv;
5133 TLVBUF_AKMP *akmp_tlv;
5134 TLVBUF_CIPHER *cipher_tlv;
5135 TLVBUF_GROUP_REKEY_TIMER *rekey_tlv;
5136 TLVBUF_WPA_PASSPHRASE *psk_tlv;
5137 TLVBUF_WEP_KEY *wep_tlv;
5138 TLVBUF_FRAG_THRESHOLD *frag_tlv;
5139 TLVBUF_STA_MAC_ADDR_FILTER *filter_tlv;
5140 TLVBUF_MAX_STA_NUM *max_sta_tlv;
5141 TLVBUF_RETRY_LIMIT *retry_limit_tlv;
5142 TLVBUF_CHANNEL_CONFIG *channel_tlv;
5143 TLVBUF_CHANNEL_LIST *chnlist_tlv;
5144 tlvbuf_custom_ie *custom_ie_tlv;
5145 custom_ie *custom_ie_ptr;
5146 tlvbuf_coex_common_cfg *coex_common_tlv;
5147 tlvbuf_coex_sco_cfg *coex_sco_tlv;
5148 tlvbuf_coex_acl_cfg *coex_acl_tlv;
5149 tlvbuf_coex_stats *coex_stats_tlv;
5150 CHANNEL_LIST *pChanList;
5152 uap_printf(MSG_DEBUG, "tlv total len=%d\n", len);
5154 while (tlvBufLeft >= (int) sizeof(TLVBUF_HEADER)) {
5155 tlvType = uap_le16_to_cpu(pCurrentTlv->Type);
5156 tlvLen = uap_le16_to_cpu(pCurrentTlv->Len);
5157 if ((sizeof(TLVBUF_HEADER) + tlvLen) > tlvBufLeft) {
5158 printf("wrong tlv: tlvLen=%d, tlvBufLeft=%d\n", tlvLen, tlvBufLeft);
5162 case MRVL_AP_MAC_ADDRESS_TLV_ID:
5163 mac_tlv = (TLVBUF_AP_MAC_ADDRESS *) pCurrentTlv;
5164 printf("AP MAC address = ");
5165 print_mac(mac_tlv->ApMacAddr);
5168 case MRVL_SSID_TLV_ID:
5169 memset(ssid, 0, sizeof(ssid));
5170 ssid_tlv = (TLVBUF_SSID *) pCurrentTlv;
5171 memcpy(ssid, ssid_tlv->Ssid, ssid_tlv->Length);
5172 printf("SSID = %s\n", ssid);
5174 case MRVL_BEACON_PERIOD_TLV_ID:
5175 beacon_tlv = (TLVBUF_BEACON_PERIOD *) pCurrentTlv;
5176 beacon_tlv->BeaconPeriod_ms =
5177 uap_le16_to_cpu(beacon_tlv->BeaconPeriod_ms);
5178 printf("Beacon period = %d\n", beacon_tlv->BeaconPeriod_ms);
5180 case MRVL_DTIM_PERIOD_TLV_ID:
5181 dtim_tlv = (TLVBUF_DTIM_PERIOD *) pCurrentTlv;
5182 printf("DTIM period = %d\n", dtim_tlv->DtimPeriod);
5184 case MRVL_CHANNELCONFIG_TLV_ID:
5185 channel_tlv = (TLVBUF_CHANNEL_CONFIG *) pCurrentTlv;
5186 printf("Channel = %d\n", channel_tlv->ChanNumber);
5187 printf("Channel Select Mode = %s\n",
5188 (channel_tlv->BandConfigType == 0) ? "Manual" : "ACS");
5190 case MRVL_CHANNELLIST_TLV_ID:
5191 chnlist_tlv = (TLVBUF_CHANNEL_LIST *) pCurrentTlv;
5192 printf("Channels List = ");
5193 pChanList = (CHANNEL_LIST *) & (chnlist_tlv->ChanList);
5194 if (chnlist_tlv->Length % sizeof(CHANNEL_LIST)) {
5197 for (i = 0; i < (chnlist_tlv->Length / sizeof(CHANNEL_LIST)); i++) {
5198 printf("%d ", pChanList->ChanNumber);
5203 case MRVL_RATES_TLV_ID:
5204 rates_tlv = (TLVBUF_RATES *) pCurrentTlv;
5205 print_rate(rates_tlv);
5207 case MRVL_TX_POWER_TLV_ID:
5208 txpower_tlv = (TLVBUF_TX_POWER *) pCurrentTlv;
5209 printf("Tx power = %d dBm\n", txpower_tlv->TxPower_dBm);
5211 case MRVL_BCAST_SSID_CTL_TLV_ID:
5212 bcast_tlv = (TLVBUF_BCAST_SSID_CTL *) pCurrentTlv;
5213 printf("SSID broadcast = %s\n",
5214 (bcast_tlv->BcastSsidCtl == 1) ? "enabled" : "disabled");
5216 case MRVL_PREAMBLE_CTL_TLV_ID:
5217 preamble_tlv = (TLVBUF_PREAMBLE_CTL *) pCurrentTlv;
5218 printf("Preamble type = %s\n", (preamble_tlv->PreambleType == 0) ?
5219 "auto" : ((preamble_tlv->PreambleType == 1) ? "short" :
5222 case MRVL_ANTENNA_CTL_TLV_ID:
5223 antenna_tlv = (TLVBUF_ANTENNA_CTL *) pCurrentTlv;
5224 printf("%s antenna = %s\n", (antenna_tlv->WhichAntenna == 0) ?
5225 "Rx" : "Tx", (antenna_tlv->AntennaMode == 0) ? "A" : "B");
5227 case MRVL_RTS_THRESHOLD_TLV_ID:
5228 rts_tlv = (TLVBUF_RTS_THRESHOLD *) pCurrentTlv;
5229 rts_tlv->RtsThreshold = uap_le16_to_cpu(rts_tlv->RtsThreshold);
5230 printf("RTS threshold = %d\n", rts_tlv->RtsThreshold);
5232 case MRVL_FRAG_THRESHOLD_TLV_ID:
5233 frag_tlv = (TLVBUF_FRAG_THRESHOLD *) pCurrentTlv;
5234 frag_tlv->FragThreshold = uap_le16_to_cpu(frag_tlv->FragThreshold);
5235 printf("Fragmentation threshold = %d\n", frag_tlv->FragThreshold);
5237 case MRVL_RADIO_CTL_TLV_ID:
5238 radio_tlv = (TLVBUF_RADIO_CTL *) pCurrentTlv;
5239 printf("Radio = %s\n", (radio_tlv->RadioCtl == 0) ? "on" : "off");
5241 case MRVL_TX_DATA_RATE_TLV_ID:
5242 txrate_tlv = (TLVBUF_TX_DATA_RATE *) pCurrentTlv;
5243 txrate_tlv->TxDataRate = uap_le16_to_cpu(txrate_tlv->TxDataRate);
5244 if (txrate_tlv->TxDataRate == 0)
5245 printf("Tx data rate = auto\n");
5247 printf("Tx data rate = 0x%x\n", txrate_tlv->TxDataRate);
5249 case MRVL_MCBC_DATA_RATE_TLV_ID:
5250 mcbcrate_tlv = (TLVBUF_MCBC_DATA_RATE *) pCurrentTlv;
5251 mcbcrate_tlv->MCBCdatarate =
5252 uap_le16_to_cpu(mcbcrate_tlv->MCBCdatarate);
5253 if (mcbcrate_tlv->MCBCdatarate == 0)
5254 printf("MCBC data rate = auto\n");
5256 printf("MCBC data rate = 0x%x\n", mcbcrate_tlv->MCBCdatarate);
5258 case MRVL_PKT_FWD_CTL_TLV_ID:
5259 pkt_fwd_tlv = (TLVBUF_PKT_FWD_CTL *) pCurrentTlv;
5260 printf("Firmware = %s\n", (pkt_fwd_tlv->PktFwdCtl == 0) ?
5261 "forwards all packets to the host" :
5262 "handles intra-BSS packets");
5264 case MRVL_STA_AGEOUT_TIMER_TLV_ID:
5265 ageout_tlv = (TLVBUF_STA_AGEOUT_TIMER *) pCurrentTlv;
5266 ageout_tlv->StaAgeoutTimer_ms =
5267 uap_le32_to_cpu(ageout_tlv->StaAgeoutTimer_ms);
5268 printf("STA ageout timer = %d\n",
5269 (int) ageout_tlv->StaAgeoutTimer_ms);
5271 case MRVL_AUTH_TLV_ID:
5272 auth_tlv = (TLVBUF_AUTH_MODE *) pCurrentTlv;
5273 print_auth(auth_tlv);
5275 case MRVL_PROTOCOL_TLV_ID:
5276 proto_tlv = (TLVBUF_PROTOCOL *) pCurrentTlv;
5277 proto_tlv->Protocol = uap_le16_to_cpu(proto_tlv->Protocol);
5278 print_protocol(proto_tlv);
5280 case MRVL_AKMP_TLV_ID:
5281 akmp_tlv = (TLVBUF_AKMP *) pCurrentTlv;
5282 if (uap_le16_to_cpu(akmp_tlv->KeyMgmt) == KEY_MGMT_PSK)
5283 printf("KeyMgmt = PSK\n");
5285 printf("KeyMgmt = NONE\n");
5287 case MRVL_CIPHER_TLV_ID:
5288 cipher_tlv = (TLVBUF_CIPHER *) pCurrentTlv;
5289 print_cipher(cipher_tlv);
5291 case MRVL_GRP_REKEY_TIME_TLV_ID:
5292 rekey_tlv = (TLVBUF_GROUP_REKEY_TIMER *) pCurrentTlv;
5293 if (rekey_tlv->GroupRekeyTime_sec == 0)
5294 printf("Group re-key time = disabled\n");
5296 printf("Group re-key time = %ld second\n",
5297 uap_le32_to_cpu(rekey_tlv->GroupRekeyTime_sec));
5299 case MRVL_WPA_PASSPHRASE_TLV_ID:
5300 psk_tlv = (TLVBUF_WPA_PASSPHRASE *) pCurrentTlv;
5301 if (psk_tlv->Length > 0) {
5302 printf("WPA passphrase = ");
5303 for (i = 0; i < psk_tlv->Length; i++)
5304 printf("%c", psk_tlv->Passphrase[i]);
5307 printf("WPA passphrase = None\n");
5309 case MRVL_WEP_KEY_TLV_ID:
5310 wep_tlv = (TLVBUF_WEP_KEY *) pCurrentTlv;
5311 print_wep_key(wep_tlv);
5313 case MRVL_STA_MAC_ADDR_FILTER_TLV_ID:
5314 filter_tlv = (TLVBUF_STA_MAC_ADDR_FILTER *) pCurrentTlv;
5315 print_mac_filter(filter_tlv);
5317 case MRVL_MAX_STA_CNT_TLV_ID:
5318 max_sta_tlv = (TLVBUF_MAX_STA_NUM *) pCurrentTlv;
5319 printf("Max Station Number = %d\n", max_sta_tlv->Max_sta_num);
5321 case MRVL_RETRY_LIMIT_TLV_ID:
5322 retry_limit_tlv = (TLVBUF_RETRY_LIMIT *) pCurrentTlv;
5323 printf("Retry Limit = %d\n", retry_limit_tlv->retry_limit);
5325 case MRVL_MGMT_IE_LIST_TLV_ID:
5326 custom_ie_tlv = (tlvbuf_custom_ie *) pCurrentTlv;
5327 custom_ie_len = tlvLen;
5328 custom_ie_ptr = (custom_ie *) (custom_ie_tlv->ie_data);
5329 while (custom_ie_len >= sizeof(custom_ie)) {
5330 printf("Index [%d]\n",
5331 uap_le16_to_cpu(custom_ie_ptr->ie_index));
5332 printf("Management Subtype Mask = 0x%02x\n",
5333 uap_le16_to_cpu(custom_ie_ptr->mgmt_subtype_mask));
5334 hexdump_data("IE Buffer", (void *) custom_ie_ptr->ie_buffer,
5335 uap_le16_to_cpu(custom_ie_ptr->ie_length), ' ');
5338 uap_le16_to_cpu(custom_ie_ptr->ie_length);
5340 (custom_ie *) ((u8 *) custom_ie_ptr + sizeof(custom_ie) +
5341 uap_le16_to_cpu(custom_ie_ptr->ie_length));
5344 case MRVL_BT_COEX_COMMON_CFG_TLV_ID:
5345 printf("Coex common configuration:\n");
5346 coex_common_tlv = (tlvbuf_coex_common_cfg *) pCurrentTlv;
5347 printf("\tConfig Bitmap = 0x%02lx\n",
5348 uap_le32_to_cpu(coex_common_tlv->config_bitmap));
5351 case MRVL_BT_COEX_SCO_CFG_TLV_ID:
5352 printf("Coex sco configuration:\n");
5353 coex_sco_tlv = (tlvbuf_coex_sco_cfg *) pCurrentTlv;
5354 for (i = 0; i < 4; i++)
5355 printf("\tQtime protection [%d] = %d usecs\n", i,
5356 uap_le16_to_cpu(coex_sco_tlv->protection_qtime[i]));
5357 printf("\tProtection frame rate = %d\n",
5358 uap_le16_to_cpu(coex_sco_tlv->protection_rate));
5359 printf("\tACL frequency = %d\n",
5360 uap_le16_to_cpu(coex_sco_tlv->acl_frequency));
5363 case MRVL_BT_COEX_ACL_CFG_TLV_ID:
5364 printf("Coex acl configuration: ");
5365 coex_acl_tlv = (tlvbuf_coex_acl_cfg *) pCurrentTlv;
5366 coex_acl_tlv->enabled = uap_le16_to_cpu(coex_acl_tlv->enabled);
5367 printf("%s\n", (coex_acl_tlv->enabled) ? "enabled" : "disabled");
5368 if (coex_acl_tlv->enabled) {
5369 printf("\tBT time = %d usecs\n",
5370 uap_le16_to_cpu(coex_acl_tlv->bt_time));
5371 printf("\tWLan time = %d usecs\n",
5372 uap_le16_to_cpu(coex_acl_tlv->wlan_time));
5373 printf("\tProtection frame rate = %d\n",
5374 uap_le16_to_cpu(coex_acl_tlv->protection_rate));
5378 case MRVL_BT_COEX_STATS_TLV_ID:
5379 printf("Coex statistics: \n");
5380 coex_stats_tlv = (tlvbuf_coex_stats *) pCurrentTlv;
5381 printf("\tNull not sent = %ld\n",
5382 uap_le32_to_cpu(coex_stats_tlv->null_not_sent));
5383 printf("\tNull queued = %ld\n",
5384 uap_le32_to_cpu(coex_stats_tlv->null_queued));
5385 printf("\tNull not queued = %ld\n",
5386 uap_le32_to_cpu(coex_stats_tlv->null_not_queued));
5387 printf("\tCF End queued = %ld\n",
5388 uap_le32_to_cpu(coex_stats_tlv->cf_end_queued));
5389 printf("\tCF End not queued = %ld\n",
5390 uap_le32_to_cpu(coex_stats_tlv->cf_end_not_queued));
5391 printf("\tNull allocation failures = %ld\n",
5392 uap_le32_to_cpu(coex_stats_tlv->null_alloc_fail));
5393 printf("\tCF End allocation failures = %ld\n",
5394 uap_le32_to_cpu(coex_stats_tlv->cf_end_alloc_fail));
5399 tlvBufLeft -= (sizeof(TLVBUF_HEADER) + tlvLen);
5400 pCurrentTlv = (TLVBUF_HEADER *) (pCurrentTlv->Data + tlvLen);
5406 * @brief Performs the ioctl operation to send the command to
5409 * @param cmd Pointer to the command buffer
5410 * @param size Pointer to the command size. This value is
5411 * overwritten by the function with the size of the
5412 * received response.
5413 * @param buf_size Size of the allocated command buffer
5414 * @return UAP_SUCCESS or UAP_FAILURE
5417 uap_ioctl(u8 * cmd, u16 * size, u16 buf_size)
5420 APCMDBUF *header = NULL;
5423 if (buf_size < *size) {
5424 printf("buf_size should not less than cmd buffer size\n");
5429 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5430 printf("ERR:Cannot open socket\n");
5433 *(u32 *) cmd = buf_size - BUF_HEADER_SIZE;
5435 /* Initialize the ifr structure */
5436 memset(&ifr, 0, sizeof(ifr));
5437 strncpy(ifr.ifr_ifrn.ifrn_name, dev_name, strlen(dev_name));
5438 ifr.ifr_ifru.ifru_data = (void *) cmd;
5439 header = (APCMDBUF *) cmd;
5440 header->Size = *size - BUF_HEADER_SIZE;
5441 if (header->CmdCode == APCMD_SYS_CONFIGURE) {
5442 APCMDBUF_SYS_CONFIGURE *sys_cfg;
5443 sys_cfg = (APCMDBUF_SYS_CONFIGURE *) cmd;
5444 sys_cfg->Action = uap_cpu_to_le16(sys_cfg->Action);
5446 endian_convert_request_header(header);
5448 /* Dump request buffer */
5449 hexdump("Request buffer", (void *) cmd, *size, ' ');
5453 if (ioctl(sockfd, UAPHOSTCMD, &ifr)) {
5455 printf("ERR:UAPHOSTCMD is not supported by %s\n", dev_name);
5459 endian_convert_response_header(header);
5460 header->CmdCode &= HostCmd_CMD_ID_MASK;
5461 header->CmdCode |= APCMD_RESP_CHECK;
5462 *size = header->Size;
5464 /* Validate response size */
5465 if (*size > (buf_size - BUF_HEADER_SIZE)) {
5467 ("ERR:Response size (%d) greater than buffer size (%d)! Aborting!\n",
5473 /* Dump respond buffer */
5474 hexdump("Respond buffer", (void *) header, header->Size + BUF_HEADER_SIZE,
5484 * @brief check cipher is valid or not
5486 * @param pairwisecipher pairwise cipher
5487 * @param groupcipher group cipher
5488 * @return UAP_SUCCESS or UAP_FAILURE
5491 is_cipher_valid(int pairwisecipher, int groupcipher)
5493 if ((pairwisecipher == CIPHER_NONE) && (groupcipher == CIPHER_NONE))
5495 if ((pairwisecipher == CIPHER_TKIP) && (groupcipher == CIPHER_TKIP))
5497 if ((pairwisecipher == CIPHER_AES_CCMP) && (groupcipher == CIPHER_AES_CCMP))
5499 if ((pairwisecipher == CIPHER_BITMAP) && (groupcipher == CIPHER_TKIP))
5505 * @brief The main function
5507 * @param argc Number of arguments
5508 * @param argv Pointer to the arguments
5512 main(int argc, char *argv[])
5515 memset(dev_name, 0, sizeof(dev_name));
5516 strcpy(dev_name, DEFAULT_DEV_NAME);
5518 /* parse arguments */
5519 while ((opt = getopt_long(argc, argv, "+hi:d:v", ap_options, NULL)) != -1) {
5522 if (strlen(optarg) < IFNAMSIZ) {
5523 memset(dev_name, 0, sizeof(dev_name));
5524 strncpy(dev_name, optarg, strlen(optarg));
5526 printf("dev_name:%s\n", dev_name);
5529 printf("uaputl.exe - uAP utility ver %s\n", UAP_VERSION);
5532 debug_level = strtoul(optarg, NULL, 10);
5533 uap_printf(MSG_DEBUG, "debug_level=%x\n", debug_level);
5551 /* process command */
5552 for (i = 0; ap_command[i].cmd; i++) {
5553 if (strncmp(ap_command[i].cmd, argv[0], strlen(ap_command[i].cmd)))
5555 if (strlen(ap_command[i].cmd) != strlen(argv[0]))
5557 ap_command[i].func(argc, argv);
5560 if (!ap_command[i].cmd) {
5561 printf("ERR: %s is not supported\n", argv[0]);