3 * @file coreconfigurator.c
6 * @sa coreconfigurator.h
12 /*****************************************************************************/
14 /*****************************************************************************/
15 #include "coreconfigurator.h"
16 /*****************************************************************************/
18 /*****************************************************************************/
19 #define INLINE static __inline
21 #define MAX_CFG_PKTLEN 1450
22 #define MSG_HEADER_LEN 4
23 #define QUERY_MSG_TYPE 'Q'
24 #define WRITE_MSG_TYPE 'W'
25 #define RESP_MSG_TYPE 'R'
26 #define WRITE_RESP_SUCCESS 1
28 #define MAC_ADDR_LEN 6
29 #define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
30 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
32 /*****************************************************************************/
34 /*****************************************************************************/
37 /*****************************************************************************/
38 /* Type Definitions */
39 /*****************************************************************************/
41 /* Basic Frame Type Codes (2-bit) */
43 FRAME_TYPE_CONTROL
= 0x04,
44 FRAME_TYPE_DATA
= 0x08,
45 FRAME_TYPE_MANAGEMENT
= 0x00,
46 FRAME_TYPE_RESERVED
= 0x0C,
47 FRAME_TYPE_FORCE_32BIT
= 0xFFFFFFFF
50 /* Frame Type and Subtype Codes (6-bit) */
81 QOS_DATA_POLL_ACK
= 0xB8,
82 QOS_NULL_FRAME
= 0xC8,
84 QOS_CFPOLL_ACK
= 0xF8,
87 FRAME_SUBTYPE_FORCE_32BIT
= 0xFFFFFFFF
90 /* Basic Frame Classes */
92 CLASS1_FRAME_TYPE
= 0x00,
93 CLASS2_FRAME_TYPE
= 0x01,
94 CLASS3_FRAME_TYPE
= 0x02,
95 FRAME_CLASS_FORCE_32BIT
= 0xFFFFFFFF
98 /* Element ID of various Information Elements */
100 ISSID
= 0, /* Service Set Identifier */
101 ISUPRATES
= 1, /* Supported Rates */
102 IFHPARMS
= 2, /* FH parameter set */
103 IDSPARMS
= 3, /* DS parameter set */
104 ICFPARMS
= 4, /* CF parameter set */
105 ITIM
= 5, /* Traffic Information Map */
106 IIBPARMS
= 6, /* IBSS parameter set */
107 ICOUNTRY
= 7, /* Country element */
108 IEDCAPARAMS
= 12, /* EDCA parameter set */
109 ITSPEC
= 13, /* Traffic Specification */
110 ITCLAS
= 14, /* Traffic Classification */
111 ISCHED
= 15, /* Schedule */
112 ICTEXT
= 16, /* Challenge Text */
113 IPOWERCONSTRAINT
= 32, /* Power Constraint */
114 IPOWERCAPABILITY
= 33, /* Power Capability */
115 ITPCREQUEST
= 34, /* TPC Request */
116 ITPCREPORT
= 35, /* TPC Report */
117 ISUPCHANNEL
= 36, /* Supported channel list */
118 ICHSWANNOUNC
= 37, /* Channel Switch Announcement */
119 IMEASUREMENTREQUEST
= 38, /* Measurement request */
120 IMEASUREMENTREPORT
= 39, /* Measurement report */
121 IQUIET
= 40, /* Quiet element Info */
122 IIBSSDFS
= 41, /* IBSS DFS */
123 IERPINFO
= 42, /* ERP Information */
124 ITSDELAY
= 43, /* TS Delay */
125 ITCLASPROCESS
= 44, /* TCLAS Processing */
126 IHTCAP
= 45, /* HT Capabilities */
127 IQOSCAP
= 46, /* QoS Capability */
128 IRSNELEMENT
= 48, /* RSN Information Element */
129 IEXSUPRATES
= 50, /* Extended Supported Rates */
130 IEXCHSWANNOUNC
= 60, /* Extended Ch Switch Announcement*/
131 IHTOPERATION
= 61, /* HT Information */
132 ISECCHOFF
= 62, /* Secondary Channel Offeset */
133 I2040COEX
= 72, /* 20/40 Coexistence IE */
134 I2040INTOLCHREPORT
= 73, /* 20/40 Intolerant channel report*/
135 IOBSSSCAN
= 74, /* OBSS Scan parameters */
136 IEXTCAP
= 127, /* Extended capability */
137 IWMM
= 221, /* WMM parameters */
138 IWPAELEMENT
= 221, /* WPA Information Element */
139 INFOELEM_ID_FORCE_32BIT
= 0xFFFFFFFF
145 s32 s32MaxRespBuffLen
;
152 /*****************************************************************************/
153 /* Extern Variable Declarations */
154 /*****************************************************************************/
157 /*****************************************************************************/
158 /* Extern Function Declarations */
159 /*****************************************************************************/
160 extern s32
SendRawPacket(s8
*ps8Packet
, s32 s32PacketLen
);
161 extern void NetworkInfoReceived(u8
*pu8Buffer
, u32 u32Length
);
162 extern void GnrlAsyncInfoReceived(u8
*pu8Buffer
, u32 u32Length
);
163 extern void host_int_ScanCompleteReceived(u8
*pu8Buffer
, u32 u32Length
);
164 /*****************************************************************************/
165 /* Global Variables */
166 /*****************************************************************************/
167 static struct semaphore SemHandleSendPkt
;
168 static struct semaphore SemHandlePktResp
;
170 static s8
*gps8ConfigPacket
;
172 static tstrConfigPktInfo gstrConfigPktInfo
;
176 static s16 g_wid_num
= -1;
180 static u8 g_oper_mode
= SET_CFG
;
183 static tstrWID gastrWIDs
[] = {
184 {WID_FIRMWARE_VERSION
, WID_STR
},
185 {WID_PHY_VERSION
, WID_STR
},
186 {WID_HARDWARE_VERSION
, WID_STR
},
187 {WID_BSS_TYPE
, WID_CHAR
},
188 {WID_QOS_ENABLE
, WID_CHAR
},
189 {WID_11I_MODE
, WID_CHAR
},
190 {WID_CURRENT_TX_RATE
, WID_CHAR
},
191 {WID_LINKSPEED
, WID_CHAR
},
192 {WID_RTS_THRESHOLD
, WID_SHORT
},
193 {WID_FRAG_THRESHOLD
, WID_SHORT
},
195 {WID_BSSID
, WID_ADR
},
196 {WID_BEACON_INTERVAL
, WID_SHORT
},
197 {WID_POWER_MANAGEMENT
, WID_CHAR
},
198 {WID_LISTEN_INTERVAL
, WID_CHAR
},
199 {WID_DTIM_PERIOD
, WID_CHAR
},
200 {WID_CURRENT_CHANNEL
, WID_CHAR
},
201 {WID_TX_POWER_LEVEL_11A
, WID_CHAR
},
202 {WID_TX_POWER_LEVEL_11B
, WID_CHAR
},
203 {WID_PREAMBLE
, WID_CHAR
},
204 {WID_11G_OPERATING_MODE
, WID_CHAR
},
205 {WID_MAC_ADDR
, WID_ADR
},
206 {WID_IP_ADDRESS
, WID_ADR
},
207 {WID_ACK_POLICY
, WID_CHAR
},
208 {WID_PHY_ACTIVE_REG
, WID_CHAR
},
209 {WID_AUTH_TYPE
, WID_CHAR
},
210 {WID_REKEY_POLICY
, WID_CHAR
},
211 {WID_REKEY_PERIOD
, WID_INT
},
212 {WID_REKEY_PACKET_COUNT
, WID_INT
},
213 {WID_11I_PSK
, WID_STR
},
214 {WID_1X_KEY
, WID_STR
},
215 {WID_1X_SERV_ADDR
, WID_IP
},
216 {WID_SUPP_USERNAME
, WID_STR
},
217 {WID_SUPP_PASSWORD
, WID_STR
},
218 {WID_USER_CONTROL_ON_TX_POWER
, WID_CHAR
},
219 {WID_MEMORY_ADDRESS
, WID_INT
},
220 {WID_MEMORY_ACCESS_32BIT
, WID_INT
},
221 {WID_MEMORY_ACCESS_16BIT
, WID_SHORT
},
222 {WID_MEMORY_ACCESS_8BIT
, WID_CHAR
},
223 {WID_SITE_SURVEY_RESULTS
, WID_STR
},
224 {WID_PMKID_INFO
, WID_STR
},
225 {WID_ASSOC_RES_INFO
, WID_STR
},
226 {WID_MANUFACTURER
, WID_STR
}, /* 4 Wids added for the CAPI tool*/
227 {WID_MODEL_NAME
, WID_STR
},
228 {WID_MODEL_NUM
, WID_STR
},
229 {WID_DEVICE_NAME
, WID_STR
},
230 {WID_SSID_PROBE_REQ
, WID_STR
},
233 {WID_11N_ENABLE
, WID_CHAR
},
234 {WID_11N_CURRENT_TX_MCS
, WID_CHAR
},
235 {WID_TX_POWER_LEVEL_11N
, WID_CHAR
},
236 {WID_11N_OPERATING_MODE
, WID_CHAR
},
237 {WID_11N_SMPS_MODE
, WID_CHAR
},
238 {WID_11N_PROT_MECH
, WID_CHAR
},
239 {WID_11N_ERP_PROT_TYPE
, WID_CHAR
},
240 {WID_11N_HT_PROT_TYPE
, WID_CHAR
},
241 {WID_11N_PHY_ACTIVE_REG_VAL
, WID_INT
},
242 {WID_11N_PRINT_STATS
, WID_CHAR
},
243 {WID_11N_AUTORATE_TABLE
, WID_BIN_DATA
},
244 {WID_HOST_CONFIG_IF_TYPE
, WID_CHAR
},
245 {WID_HOST_DATA_IF_TYPE
, WID_CHAR
},
246 {WID_11N_SIG_QUAL_VAL
, WID_SHORT
},
247 {WID_11N_IMMEDIATE_BA_ENABLED
, WID_CHAR
},
248 {WID_11N_TXOP_PROT_DISABLE
, WID_CHAR
},
249 {WID_11N_SHORT_GI_20MHZ_ENABLE
, WID_CHAR
},
250 {WID_SHORT_SLOT_ALLOWED
, WID_CHAR
},
251 {WID_11W_ENABLE
, WID_CHAR
},
252 {WID_11W_MGMT_PROT_REQ
, WID_CHAR
},
253 {WID_2040_ENABLE
, WID_CHAR
},
254 {WID_2040_COEXISTENCE
, WID_CHAR
},
255 {WID_USER_SEC_CHANNEL_OFFSET
, WID_CHAR
},
256 {WID_2040_CURR_CHANNEL_OFFSET
, WID_CHAR
},
257 {WID_2040_40MHZ_INTOLERANT
, WID_CHAR
},
258 {WID_HUT_RESTART
, WID_CHAR
},
259 {WID_HUT_NUM_TX_PKTS
, WID_INT
},
260 {WID_HUT_FRAME_LEN
, WID_SHORT
},
261 {WID_HUT_TX_FORMAT
, WID_CHAR
},
262 {WID_HUT_BANDWIDTH
, WID_CHAR
},
263 {WID_HUT_OP_BAND
, WID_CHAR
},
264 {WID_HUT_STBC
, WID_CHAR
},
265 {WID_HUT_ESS
, WID_CHAR
},
266 {WID_HUT_ANTSET
, WID_CHAR
},
267 {WID_HUT_HT_OP_MODE
, WID_CHAR
},
268 {WID_HUT_RIFS_MODE
, WID_CHAR
},
269 {WID_HUT_SMOOTHING_REC
, WID_CHAR
},
270 {WID_HUT_SOUNDING_PKT
, WID_CHAR
},
271 {WID_HUT_HT_CODING
, WID_CHAR
},
272 {WID_HUT_TEST_DIR
, WID_CHAR
},
273 {WID_HUT_TXOP_LIMIT
, WID_SHORT
},
274 {WID_HUT_DEST_ADDR
, WID_ADR
},
275 {WID_HUT_TX_PATTERN
, WID_BIN_DATA
},
276 {WID_HUT_TX_TIME_TAKEN
, WID_INT
},
277 {WID_HUT_PHY_TEST_MODE
, WID_CHAR
},
278 {WID_HUT_PHY_TEST_RATE_HI
, WID_CHAR
},
279 {WID_HUT_PHY_TEST_RATE_LO
, WID_CHAR
},
280 {WID_HUT_TX_TEST_TIME
, WID_INT
},
281 {WID_HUT_LOG_INTERVAL
, WID_INT
},
282 {WID_HUT_DISABLE_RXQ_REPLENISH
, WID_CHAR
},
283 {WID_HUT_TEST_ID
, WID_STR
},
284 {WID_HUT_KEY_ORIGIN
, WID_CHAR
},
285 {WID_HUT_BCST_PERCENT
, WID_CHAR
},
286 {WID_HUT_GROUP_CIPHER_TYPE
, WID_CHAR
},
287 {WID_HUT_STATS
, WID_BIN_DATA
},
288 {WID_HUT_TSF_TEST_MODE
, WID_CHAR
},
289 {WID_HUT_SIG_QUAL_AVG
, WID_SHORT
},
290 {WID_HUT_SIG_QUAL_AVG_CNT
, WID_SHORT
},
291 {WID_HUT_TSSI_VALUE
, WID_CHAR
},
292 {WID_HUT_MGMT_PERCENT
, WID_CHAR
},
293 {WID_HUT_MGMT_BCST_PERCENT
, WID_CHAR
},
294 {WID_HUT_MGMT_ALLOW_HT
, WID_CHAR
},
295 {WID_HUT_UC_MGMT_TYPE
, WID_CHAR
},
296 {WID_HUT_BC_MGMT_TYPE
, WID_CHAR
},
297 {WID_HUT_UC_MGMT_FRAME_LEN
, WID_SHORT
},
298 {WID_HUT_BC_MGMT_FRAME_LEN
, WID_SHORT
},
299 {WID_HUT_11W_MFP_REQUIRED_TX
, WID_CHAR
},
300 {WID_HUT_11W_MFP_PEER_CAPABLE
, WID_CHAR
},
301 {WID_HUT_11W_TX_IGTK_ID
, WID_CHAR
},
302 {WID_HUT_FC_TXOP_MOD
, WID_CHAR
},
303 {WID_HUT_FC_PROT_TYPE
, WID_CHAR
},
304 {WID_HUT_SEC_CCA_ASSERT
, WID_CHAR
},
305 #endif /* MAC_802_11N */
308 u16 g_num_total_switches
= (sizeof(gastrWIDs
) / sizeof(tstrWID
));
309 /*****************************************************************************/
310 /* Static Function Declarations */
311 /*****************************************************************************/
315 /*****************************************************************************/
317 /*****************************************************************************/
318 INLINE u8
ascii_hex_to_dec(u8 num
)
320 if ((num
>= '0') && (num
<= '9'))
322 else if ((num
>= 'A') && (num
<= 'F'))
323 return (10 + (num
- 'A'));
324 else if ((num
>= 'a') && (num
<= 'f'))
325 return (10 + (num
- 'a'));
330 INLINE u8
get_hex_char(u8 inp
)
332 u8
*d2htab
= "0123456789ABCDEF";
334 return d2htab
[inp
& 0xF];
337 /* This function extracts the MAC address held in a string in standard format */
338 /* into another buffer as integers. */
339 INLINE u16
extract_mac_addr(char *str
, u8
*buff
)
342 while (*str
!= '\0') {
343 if ((*str
== ':') || (*str
== '-'))
346 *buff
= (*buff
<< 4) + ascii_hex_to_dec(*str
);
354 /* This function creates MAC address in standard format from a buffer of */
356 INLINE
void create_mac_addr(u8
*str
, u8
*buff
)
361 for (i
= 0; i
< MAC_ADDR_LEN
; i
++) {
362 str
[j
++] = get_hex_char((u8
)((buff
[i
] >> 4) & 0x0F));
363 str
[j
++] = get_hex_char((u8
)(buff
[i
] & 0x0F));
369 /* This function converts the IP address string in dotted decimal format to */
370 /* unsigned integer. This functionality is similar to the library function */
371 /* inet_addr() but is reimplemented here since I could not confirm that */
372 /* inet_addr is platform independent. */
373 /* ips=>IP Address String in dotted decimal format */
374 /* ipn=>Pointer to IP Address in integer format */
375 INLINE u8
conv_ip_to_int(u8
*ips
, u32
*ipn
)
380 /* Integer to string for each component */
381 while (ips
[i
] != '\0') {
383 *ipn
= ((*ipn
) << 8) | ipb
;
386 ipb
= ipb
* 10 + ascii_hex_to_dec(ips
[i
]);
392 /* The last byte of the IP address is read in here */
393 *ipn
= ((*ipn
) << 8) | ipb
;
398 /* This function converts the IP address from integer format to dotted */
399 /* decimal string format. Alternative to std library fn inet_ntoa(). */
400 /* ips=>Buffer to hold IP Address String dotted decimal format (Min 17B) */
401 /* ipn=>IP Address in integer format */
402 INLINE u8
conv_int_to_ip(u8
*ips
, u32 ipn
)
409 for (cnt
= 4; cnt
> 0; cnt
--) {
410 ipb
= (ipn
>> (8 * (cnt
- 1))) & 0xFF;
421 ips
[i
++] = get_hex_char(ipb
/ 100);
425 ips
[i
++] = get_hex_char(ipb
/ 10);
429 ips
[i
++] = get_hex_char(ipb
);
441 INLINE tenuWIDtype
get_wid_type(u32 wid_num
)
443 /* Check for iconfig specific WID types first */
444 if ((wid_num
== WID_BSSID
) ||
445 (wid_num
== WID_MAC_ADDR
) ||
446 (wid_num
== WID_IP_ADDRESS
) ||
447 (wid_num
== WID_HUT_DEST_ADDR
)) {
451 if ((WID_1X_SERV_ADDR
== wid_num
) ||
452 (WID_STACK_IP_ADDR
== wid_num
) ||
453 (WID_STACK_NETMASK_ADDR
== wid_num
)) {
457 /* Next check for standard WID types */
458 if (wid_num
< 0x1000)
460 else if (wid_num
< 0x2000)
462 else if (wid_num
< 0x3000)
464 else if (wid_num
< 0x4000)
466 else if (wid_num
< 0x5000)
473 /* This function extracts the beacon period field from the beacon or probe */
474 /* response frame. */
475 INLINE u16
get_beacon_period(u8
*data
)
480 bcn_per
|= (data
[1] << 8);
485 INLINE u32
get_beacon_timestamp_lo(u8
*data
)
488 u32 index
= MAC_HDR_LEN
;
490 time_stamp
|= data
[index
++];
491 time_stamp
|= (data
[index
++] << 8);
492 time_stamp
|= (data
[index
++] << 16);
493 time_stamp
|= (data
[index
] << 24);
498 INLINE u32
get_beacon_timestamp_hi(u8
*data
)
501 u32 index
= (MAC_HDR_LEN
+ 4);
503 time_stamp
|= data
[index
++];
504 time_stamp
|= (data
[index
++] << 8);
505 time_stamp
|= (data
[index
++] << 16);
506 time_stamp
|= (data
[index
] << 24);
511 /* This function extracts the 'frame type' bits from the MAC header of the */
513 /* Returns the value in the LSB of the returned value. */
514 INLINE tenuBasicFrmType
get_type(u8
*header
)
516 return ((tenuBasicFrmType
)(header
[0] & 0x0C));
519 /* This function extracts the 'frame type and sub type' bits from the MAC */
520 /* header of the input frame. */
521 /* Returns the value in the LSB of the returned value. */
522 INLINE tenuFrmSubtype
get_sub_type(u8
*header
)
524 return ((tenuFrmSubtype
)(header
[0] & 0xFC));
527 /* This function extracts the 'to ds' bit from the MAC header of the input */
529 /* Returns the value in the LSB of the returned value. */
530 INLINE u8
get_to_ds(u8
*header
)
532 return (header
[1] & 0x01);
535 /* This function extracts the 'from ds' bit from the MAC header of the input */
537 /* Returns the value in the LSB of the returned value. */
538 INLINE u8
get_from_ds(u8
*header
)
540 return ((header
[1] & 0x02) >> 1);
543 /* This function extracts the MAC Address in 'address1' field of the MAC */
544 /* header and updates the MAC Address in the allocated 'addr' variable. */
545 INLINE
void get_address1(u8
*pu8msa
, u8
*addr
)
547 memcpy(addr
, pu8msa
+ 4, 6);
550 /* This function extracts the MAC Address in 'address2' field of the MAC */
551 /* header and updates the MAC Address in the allocated 'addr' variable. */
552 INLINE
void get_address2(u8
*pu8msa
, u8
*addr
)
554 memcpy(addr
, pu8msa
+ 10, 6);
557 /* This function extracts the MAC Address in 'address3' field of the MAC */
558 /* header and updates the MAC Address in the allocated 'addr' variable. */
559 INLINE
void get_address3(u8
*pu8msa
, u8
*addr
)
561 memcpy(addr
, pu8msa
+ 16, 6);
564 /* This function extracts the BSSID from the incoming WLAN packet based on */
565 /* the 'from ds' bit, and updates the MAC Address in the allocated 'addr' */
567 INLINE
void get_BSSID(u8
*data
, u8
*bssid
)
569 if (get_from_ds(data
) == 1)
570 get_address2(data
, bssid
);
571 else if (get_to_ds(data
) == 1)
572 get_address1(data
, bssid
);
574 get_address3(data
, bssid
);
577 /* This function extracts the SSID from a beacon/probe response frame */
578 INLINE
void get_ssid(u8
*data
, u8
*ssid
, u8
*p_ssid_len
)
584 len
= data
[MAC_HDR_LEN
+ TIME_STAMP_LEN
+ BEACON_INTERVAL_LEN
+
586 j
= MAC_HDR_LEN
+ TIME_STAMP_LEN
+ BEACON_INTERVAL_LEN
+
589 /* If the SSID length field is set wrongly to a value greater than the */
590 /* allowed maximum SSID length limit, reset the length to 0 */
591 if (len
>= MAX_SSID_LEN
)
594 for (i
= 0; i
< len
; i
++, j
++)
602 /* This function extracts the capability info field from the beacon or probe */
603 /* response frame. */
604 INLINE u16
get_cap_info(u8
*data
)
607 u16 index
= MAC_HDR_LEN
;
610 st
= get_sub_type(data
);
612 /* Location of the Capability field is different for Beacon and */
613 /* Association frames. */
614 if ((st
== BEACON
) || (st
== PROBE_RSP
))
615 index
+= TIME_STAMP_LEN
+ BEACON_INTERVAL_LEN
;
617 cap_info
= data
[index
];
618 cap_info
|= (data
[index
+ 1] << 8);
623 /* This function extracts the capability info field from the Association */
624 /* response frame. */
625 INLINE u16
get_assoc_resp_cap_info(u8
*data
)
630 cap_info
|= (data
[1] << 8);
635 /* This funcion extracts the association status code from the incoming */
636 /* association response frame and returns association status code */
637 INLINE u16
get_asoc_status(u8
*data
)
641 asoc_status
= data
[3];
642 asoc_status
= (asoc_status
<< 8) | data
[2];
647 /* This function extracts association ID from the incoming association */
649 INLINE u16
get_asoc_id(u8
*data
)
654 asoc_id
|= (data
[5] << 8);
660 * @brief initializes the Core Configurator
662 * @return Error code indicating success/failure
669 s32
CoreConfiguratorInit(void)
671 s32 s32Error
= WILC_SUCCESS
;
672 PRINT_D(CORECONFIG_DBG
, "CoreConfiguratorInit()\n");
674 sema_init(&SemHandleSendPkt
, 1);
675 sema_init(&SemHandlePktResp
, 0);
677 gps8ConfigPacket
= (s8
*)WILC_MALLOC(MAX_PACKET_BUFF_SIZE
);
678 if (gps8ConfigPacket
== NULL
) {
679 PRINT_ER("failed in gps8ConfigPacket allocation\n");
680 s32Error
= WILC_NO_MEM
;
684 memset((void *)gps8ConfigPacket
, 0, MAX_PACKET_BUFF_SIZE
);
686 memset((void *)(&gstrConfigPktInfo
), 0, sizeof(tstrConfigPktInfo
));
691 u8
*get_tim_elm(u8
*pu8msa
, u16 u16RxLen
, u16 u16TagParamOffset
)
695 /*************************************************************************/
696 /* Beacon Frame - Frame Body */
697 /* --------------------------------------------------------------------- */
698 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
699 /* --------------------------------------------------------------------- */
700 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
701 /* --------------------------------------------------------------------- */
703 /*************************************************************************/
705 u16index
= u16TagParamOffset
;
707 /* Search for the TIM Element Field and return if the element is found */
708 while (u16index
< (u16RxLen
- FCS_LEN
)) {
709 if (pu8msa
[u16index
] == ITIM
)
710 return &pu8msa
[u16index
];
712 u16index
+= (IE_HDR_LEN
+ pu8msa
[u16index
+ 1]);
718 /* This function gets the current channel information from
719 * the 802.11n beacon/probe response frame */
720 u8
get_current_channel_802_11n(u8
*pu8msa
, u16 u16RxLen
)
724 index
= TAG_PARAM_OFFSET
;
725 while (index
< (u16RxLen
- FCS_LEN
)) {
726 if (pu8msa
[index
] == IDSPARMS
)
727 return pu8msa
[index
+ 2];
729 /* Increment index by length information and header */
730 index
+= pu8msa
[index
+ 1] + IE_HDR_LEN
;
733 /* Return current channel information from the MIB, if beacon/probe */
734 /* response frame does not contain the DS parameter set IE */
735 /* return (mget_CurrentChannel() + 1); */
736 return 0; /* no MIB here */
739 u8
get_current_channel(u8
*pu8msa
, u16 u16RxLen
)
743 /* Get the current channel as its not set in */
744 /* 802.11a beacons/probe response */
745 return (get_rf_channel() + 1);
746 #else /* FIVE_GHZ_BAND */
747 /* Extract current channel information from */
748 /* the beacon/probe response frame */
749 return get_current_channel_802_11n(pu8msa
, u16RxLen
);
750 #endif /* FIVE_GHZ_BAND */
753 #endif /* PHY_802_11n */
757 * @brief parses the received 'N' message
759 * @param[in] pu8MsgBuffer The message to be parsed
760 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
761 * @return Error code indicating success/failure
767 s32
ParseNetworkInfo(u8
*pu8MsgBuffer
, tstrNetworkInfo
**ppstrNetworkInfo
)
769 s32 s32Error
= WILC_SUCCESS
;
770 tstrNetworkInfo
*pstrNetworkInfo
= NULL
;
775 u16 u16WidID
= (u16
)WID_NIL
;
779 u8MsgType
= pu8MsgBuffer
[0];
781 /* Check whether the received message type is 'N' */
782 if ('N' != u8MsgType
) {
783 PRINT_ER("Received Message format incorrect.\n");
784 WILC_ERRORREPORT(s32Error
, WILC_FAIL
);
787 /* Extract message ID */
788 u8MsgID
= pu8MsgBuffer
[1];
790 /* Extract message Length */
791 u16MsgLen
= MAKE_WORD16(pu8MsgBuffer
[2], pu8MsgBuffer
[3]);
794 u16WidID
= MAKE_WORD16(pu8MsgBuffer
[4], pu8MsgBuffer
[5]);
796 /* Extract WID Length */
797 u16WidLen
= MAKE_WORD16(pu8MsgBuffer
[6], pu8MsgBuffer
[7]);
799 /* Assign a pointer to the WID value */
800 pu8WidVal
= &pu8MsgBuffer
[8];
802 /* parse the WID value of the WID "WID_NEWORK_INFO" */
813 pstrNetworkInfo
= (tstrNetworkInfo
*)WILC_MALLOC(sizeof(tstrNetworkInfo
));
814 memset((void *)(pstrNetworkInfo
), 0, sizeof(tstrNetworkInfo
));
816 pstrNetworkInfo
->s8rssi
= pu8WidVal
[0];
818 /* Assign a pointer to msa "Mac Header Start Address" */
819 pu8msa
= &pu8WidVal
[1];
821 u16RxLen
= u16WidLen
- 1;
825 /* Get the cap_info */
826 pstrNetworkInfo
->u16CapInfo
= get_cap_info(pu8msa
);
828 /* Get time-stamp [Low only 32 bit] */
829 pstrNetworkInfo
->u32Tsf
= get_beacon_timestamp_lo(pu8msa
);
830 PRINT_D(CORECONFIG_DBG
, "TSF :%x\n", pstrNetworkInfo
->u32Tsf
);
833 /* Get full time-stamp [Low and High 64 bit] */
834 u32Tsf_Lo
= get_beacon_timestamp_lo(pu8msa
);
835 u32Tsf_Hi
= get_beacon_timestamp_hi(pu8msa
);
837 pstrNetworkInfo
->u64Tsf
= u32Tsf_Lo
| ((u64
)u32Tsf_Hi
<< 32);
840 get_ssid(pu8msa
, pstrNetworkInfo
->au8ssid
, &(pstrNetworkInfo
->u8SsidLen
));
843 get_BSSID(pu8msa
, pstrNetworkInfo
->au8bssid
);
845 /* Get the current channel */
846 pstrNetworkInfo
->u8channel
= get_current_channel(pu8msa
, (u16RxLen
+ FCS_LEN
));
848 /* Get beacon period */
849 u8index
= (MAC_HDR_LEN
+ TIME_STAMP_LEN
);
851 pstrNetworkInfo
->u16BeaconPeriod
= get_beacon_period(pu8msa
+ u8index
);
853 u8index
+= BEACON_INTERVAL_LEN
+ CAP_INFO_LEN
;
855 /* Get DTIM Period */
856 pu8TimElm
= get_tim_elm(pu8msa
, (u16RxLen
+ FCS_LEN
), u8index
);
858 pstrNetworkInfo
->u8DtimPeriod
= pu8TimElm
[3];
859 pu8IEs
= &pu8msa
[MAC_HDR_LEN
+ TIME_STAMP_LEN
+ BEACON_INTERVAL_LEN
+ CAP_INFO_LEN
];
860 u16IEsLen
= u16RxLen
- (MAC_HDR_LEN
+ TIME_STAMP_LEN
+ BEACON_INTERVAL_LEN
+ CAP_INFO_LEN
);
863 pstrNetworkInfo
->pu8IEs
= (u8
*)WILC_MALLOC(u16IEsLen
);
864 memset((void *)(pstrNetworkInfo
->pu8IEs
), 0, u16IEsLen
);
866 memcpy(pstrNetworkInfo
->pu8IEs
, pu8IEs
, u16IEsLen
);
868 pstrNetworkInfo
->u16IEsLen
= u16IEsLen
;
872 *ppstrNetworkInfo
= pstrNetworkInfo
;
879 * @brief Deallocates the parsed Network Info
881 * @param[in] pstrNetworkInfo Network Info to be deallocated
882 * @return Error code indicating success/failure
888 s32
DeallocateNetworkInfo(tstrNetworkInfo
*pstrNetworkInfo
)
890 s32 s32Error
= WILC_SUCCESS
;
892 if (pstrNetworkInfo
!= NULL
) {
893 if (pstrNetworkInfo
->pu8IEs
!= NULL
) {
894 kfree(pstrNetworkInfo
->pu8IEs
);
895 pstrNetworkInfo
->pu8IEs
= NULL
;
897 s32Error
= WILC_FAIL
;
900 kfree(pstrNetworkInfo
);
901 pstrNetworkInfo
= NULL
;
904 s32Error
= WILC_FAIL
;
911 * @brief parses the received Association Response frame
913 * @param[in] pu8Buffer The Association Response frame to be parsed
914 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
915 * @return Error code indicating success/failure
921 s32
ParseAssocRespInfo(u8
*pu8Buffer
, u32 u32BufferLen
,
922 tstrConnectRespInfo
**ppstrConnectRespInfo
)
924 s32 s32Error
= WILC_SUCCESS
;
925 tstrConnectRespInfo
*pstrConnectRespInfo
= NULL
;
926 u16 u16AssocRespLen
= 0;
930 pstrConnectRespInfo
= (tstrConnectRespInfo
*)WILC_MALLOC(sizeof(tstrConnectRespInfo
));
931 memset((void *)(pstrConnectRespInfo
), 0, sizeof(tstrConnectRespInfo
));
933 /* u16AssocRespLen = pu8Buffer[0]; */
934 u16AssocRespLen
= (u16
)u32BufferLen
;
936 /* get the status code */
937 pstrConnectRespInfo
->u16ConnectStatus
= get_asoc_status(pu8Buffer
);
938 if (pstrConnectRespInfo
->u16ConnectStatus
== SUCCESSFUL_STATUSCODE
) {
940 /* get the capability */
941 pstrConnectRespInfo
->u16capability
= get_assoc_resp_cap_info(pu8Buffer
);
943 /* get the Association ID */
944 pstrConnectRespInfo
->u16AssocID
= get_asoc_id(pu8Buffer
);
946 /* get the Information Elements */
947 pu8IEs
= &pu8Buffer
[CAP_INFO_LEN
+ STATUS_CODE_LEN
+ AID_LEN
];
948 u16IEsLen
= u16AssocRespLen
- (CAP_INFO_LEN
+ STATUS_CODE_LEN
+ AID_LEN
);
950 pstrConnectRespInfo
->pu8RespIEs
= (u8
*)WILC_MALLOC(u16IEsLen
);
951 memset((void *)(pstrConnectRespInfo
->pu8RespIEs
), 0, u16IEsLen
);
953 memcpy(pstrConnectRespInfo
->pu8RespIEs
, pu8IEs
, u16IEsLen
);
954 pstrConnectRespInfo
->u16RespIEsLen
= u16IEsLen
;
957 *ppstrConnectRespInfo
= pstrConnectRespInfo
;
964 * @brief Deallocates the parsed Association Response Info
966 * @param[in] pstrNetworkInfo Network Info to be deallocated
967 * @return Error code indicating success/failure
973 s32
DeallocateAssocRespInfo(tstrConnectRespInfo
*pstrConnectRespInfo
)
975 s32 s32Error
= WILC_SUCCESS
;
977 if (pstrConnectRespInfo
!= NULL
) {
978 if (pstrConnectRespInfo
->pu8RespIEs
!= NULL
) {
979 kfree(pstrConnectRespInfo
->pu8RespIEs
);
980 pstrConnectRespInfo
->pu8RespIEs
= NULL
;
982 s32Error
= WILC_FAIL
;
985 kfree(pstrConnectRespInfo
);
986 pstrConnectRespInfo
= NULL
;
989 s32Error
= WILC_FAIL
;
995 #ifndef CONNECT_DIRECT
996 s32
ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults
[][MAX_SURVEY_RESULT_FRAG_SIZE
],
997 wid_site_survey_reslts_s
**ppstrSurveyResults
,
998 u32
*pu32SurveyResultsCount
)
1000 s32 s32Error
= WILC_SUCCESS
;
1001 wid_site_survey_reslts_s
*pstrSurveyResults
= NULL
;
1002 u32 u32SurveyResultsCount
= 0;
1003 u32 u32SurveyBytesLength
= 0;
1005 u32 u32RcvdSurveyResultsNum
= 2;
1006 u8 u8ReadSurveyResFragNum
;
1010 for (i
= 0; i
< u32RcvdSurveyResultsNum
; i
++) {
1011 u32SurveyBytesLength
= ppu8RcvdSiteSurveyResults
[i
][0];
1014 for (j
= 0; j
< u32SurveyBytesLength
; j
+= SURVEY_RESULT_LENGTH
) {
1015 u32SurveyResultsCount
++;
1019 pstrSurveyResults
= (wid_site_survey_reslts_s
*)WILC_MALLOC(u32SurveyResultsCount
* sizeof(wid_site_survey_reslts_s
));
1020 if (pstrSurveyResults
== NULL
) {
1021 u32SurveyResultsCount
= 0;
1022 WILC_ERRORREPORT(s32Error
, WILC_NO_MEM
);
1025 memset((void *)(pstrSurveyResults
), 0, u32SurveyResultsCount
* sizeof(wid_site_survey_reslts_s
));
1027 u32SurveyResultsCount
= 0;
1029 for (i
= 0; i
< u32RcvdSurveyResultsNum
; i
++) {
1030 pu8BufferPtr
= ppu8RcvdSiteSurveyResults
[i
];
1032 u32SurveyBytesLength
= pu8BufferPtr
[0];
1034 /* TODO: mostafa: pu8BufferPtr[1] contains the fragment num */
1035 u8ReadSurveyResFragNum
= pu8BufferPtr
[1];
1039 for (j
= 0; j
< u32SurveyBytesLength
; j
+= SURVEY_RESULT_LENGTH
) {
1040 memcpy(&pstrSurveyResults
[u32SurveyResultsCount
], pu8BufferPtr
, SURVEY_RESULT_LENGTH
);
1041 pu8BufferPtr
+= SURVEY_RESULT_LENGTH
;
1042 u32SurveyResultsCount
++;
1047 *ppstrSurveyResults
= pstrSurveyResults
;
1048 *pu32SurveyResultsCount
= u32SurveyResultsCount
;
1054 s32
DeallocateSurveyResults(wid_site_survey_reslts_s
*pstrSurveyResults
)
1056 s32 s32Error
= WILC_SUCCESS
;
1058 if (pstrSurveyResults
!= NULL
) {
1059 kfree(pstrSurveyResults
);
1066 /*****************************************************************************/
1068 /* Function Name : ProcessCharWid */
1070 /* Description : This function processes a WID of type WID_CHAR and */
1071 /* updates the cfg packet with the supplied value. */
1073 /* Inputs : 1) Pointer to WID cfg structure */
1074 /* 2) Value to set */
1080 /* Outputs : None */
1082 /* Returns : None */
1086 /* Revision History: */
1088 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1089 /* 08 01 2008 Ittiam Draft */
1091 /*****************************************************************************/
1093 void ProcessCharWid(char *pcPacket
, s32
*ps32PktLen
,
1094 tstrWID
*pstrWID
, s8
*ps8WidVal
)
1096 u8
*pu8val
= (u8
*)ps8WidVal
;
1098 s32 s32PktLen
= *ps32PktLen
;
1099 if (pstrWID
== NULL
) {
1100 PRINT_WRN(CORECONFIG_DBG
, "Can't set CHAR val 0x%x ,NULL structure\n", u8val
);
1105 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1106 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
>> 8) & 0xFF;
1107 if (g_oper_mode
== SET_CFG
) {
1111 pcPacket
[s32PktLen
++] = sizeof(u8
);
1115 pcPacket
[s32PktLen
++] = u8val
;
1117 *ps32PktLen
= s32PktLen
;
1120 /*****************************************************************************/
1122 /* Function Name : ProcessShortWid */
1124 /* Description : This function processes a WID of type WID_SHORT and */
1125 /* updates the cfg packet with the supplied value. */
1127 /* Inputs : 1) Pointer to WID cfg structure */
1128 /* 2) Value to set */
1134 /* Outputs : None */
1136 /* Returns : None */
1140 /* Revision History: */
1142 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1143 /* 08 01 2008 Ittiam Draft */
1145 /*****************************************************************************/
1147 void ProcessShortWid(char *pcPacket
, s32
*ps32PktLen
,
1148 tstrWID
*pstrWID
, s8
*ps8WidVal
)
1150 u16
*pu16val
= (u16
*)ps8WidVal
;
1152 s32 s32PktLen
= *ps32PktLen
;
1153 if (pstrWID
== NULL
) {
1154 PRINT_WRN(CORECONFIG_DBG
, "Can't set SHORT val 0x%x ,NULL structure\n", u16val
);
1159 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1160 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1162 if (g_oper_mode
== SET_CFG
) {
1166 pcPacket
[s32PktLen
++] = sizeof(u16
);
1169 pcPacket
[s32PktLen
++] = (u8
)(u16val
& 0xFF);
1170 pcPacket
[s32PktLen
++] = (u8
)((u16val
>> 8) & 0xFF);
1172 *ps32PktLen
= s32PktLen
;
1175 /*****************************************************************************/
1177 /* Function Name : ProcessIntWid */
1179 /* Description : This function processes a WID of type WID_INT and */
1180 /* updates the cfg packet with the supplied value. */
1182 /* Inputs : 1) Pointer to WID cfg structure */
1183 /* 2) Value to set */
1189 /* Outputs : None */
1191 /* Returns : None */
1195 /* Revision History: */
1197 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1198 /* 08 01 2008 Ittiam Draft */
1200 /*****************************************************************************/
1202 void ProcessIntWid(char *pcPacket
, s32
*ps32PktLen
,
1203 tstrWID
*pstrWID
, s8
*ps8WidVal
)
1205 u32
*pu32val
= (u32
*)ps8WidVal
;
1207 s32 s32PktLen
= *ps32PktLen
;
1208 if (pstrWID
== NULL
) {
1209 PRINT_WRN(CORECONFIG_DBG
, "Can't set INT val 0x%x , NULL structure\n", u32val
);
1214 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1215 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1217 if (g_oper_mode
== SET_CFG
) {
1221 pcPacket
[s32PktLen
++] = sizeof(u32
);
1224 pcPacket
[s32PktLen
++] = (u8
)(u32val
& 0xFF);
1225 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 8) & 0xFF);
1226 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 16) & 0xFF);
1227 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 24) & 0xFF);
1229 *ps32PktLen
= s32PktLen
;
1232 /*****************************************************************************/
1234 /* Function Name : ProcessIPwid */
1236 /* Description : This function processes a WID of type WID_IP and */
1237 /* updates the cfg packet with the supplied value. */
1239 /* Inputs : 1) Pointer to WID cfg structure */
1240 /* 2) Value to set */
1247 /* Outputs : None */
1249 /* Returns : None */
1253 /* Revision History: */
1255 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1256 /* 08 01 2008 Ittiam Draft */
1258 /*****************************************************************************/
1260 void ProcessIPwid(char *pcPacket
, s32
*ps32PktLen
,
1261 tstrWID
*pstrWID
, u8
*pu8ip
)
1264 s32 s32PktLen
= *ps32PktLen
;
1266 if (pstrWID
== NULL
) {
1267 PRINT_WRN(CORECONFIG_DBG
, "Can't set IP Addr , NULL structure\n");
1272 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1273 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1275 if (g_oper_mode
== SET_CFG
) {
1277 pcPacket
[s32PktLen
++] = sizeof(u32
);
1279 /* Convert the IP Address String to Integer */
1280 conv_ip_to_int(pu8ip
, &u32val
);
1283 pcPacket
[s32PktLen
++] = (u8
)(u32val
& 0xFF);
1284 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 8) & 0xFF);
1285 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 16) & 0xFF);
1286 pcPacket
[s32PktLen
++] = (u8
)((u32val
>> 24) & 0xFF);
1288 *ps32PktLen
= s32PktLen
;
1291 /*****************************************************************************/
1293 /* Function Name : ProcessStrWid */
1295 /* Description : This function processes a WID of type WID_STR and */
1296 /* updates the cfg packet with the supplied value. */
1298 /* Inputs : 1) Pointer to WID cfg structure */
1299 /* 2) Value to set */
1305 /* Outputs : None */
1307 /* Returns : None */
1311 /* Revision History: */
1313 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1314 /* 08 01 2008 Ittiam Draft */
1316 /*****************************************************************************/
1318 void ProcessStrWid(char *pcPacket
, s32
*ps32PktLen
,
1319 tstrWID
*pstrWID
, u8
*pu8val
, s32 s32ValueSize
)
1323 s32 s32PktLen
= *ps32PktLen
;
1324 if (pstrWID
== NULL
) {
1325 PRINT_WRN(CORECONFIG_DBG
, "Can't set STR val, NULL structure\n");
1330 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1331 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1333 if (g_oper_mode
== SET_CFG
) {
1334 /* Message Length */
1335 u16MsgLen
= (u16
)s32ValueSize
;
1338 pcPacket
[s32PktLen
++] = (u8
)u16MsgLen
;
1341 for (idx
= 0; idx
< u16MsgLen
; idx
++)
1342 pcPacket
[s32PktLen
++] = pu8val
[idx
];
1344 *ps32PktLen
= s32PktLen
;
1347 /*****************************************************************************/
1349 /* Function Name : ProcessAdrWid */
1351 /* Description : This function processes a WID of type WID_ADR and */
1352 /* updates the cfg packet with the supplied value. */
1354 /* Inputs : 1) Pointer to WID cfg structure */
1355 /* 2) Value to set */
1361 /* Outputs : None */
1363 /* Returns : None */
1367 /* Revision History: */
1369 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1370 /* 08 01 2008 Ittiam Draft */
1372 /*****************************************************************************/
1374 void ProcessAdrWid(char *pcPacket
, s32
*ps32PktLen
,
1375 tstrWID
*pstrWID
, u8
*pu8val
)
1378 s32 s32PktLen
= *ps32PktLen
;
1380 if (pstrWID
== NULL
) {
1381 PRINT_WRN(CORECONFIG_DBG
, "Can't set Addr WID, NULL structure\n");
1386 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1387 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1389 if (g_oper_mode
== SET_CFG
) {
1390 /* Message Length */
1391 u16MsgLen
= MAC_ADDR_LEN
;
1394 pcPacket
[s32PktLen
++] = (u8
)u16MsgLen
;
1397 extract_mac_addr(pu8val
, pcPacket
+ s32PktLen
);
1398 s32PktLen
+= u16MsgLen
;
1400 *ps32PktLen
= s32PktLen
;
1403 /*****************************************************************************/
1405 /* Function Name : ProcessBinWid */
1407 /* Description : This function processes a WID of type WID_BIN_DATA and */
1408 /* updates the cfg packet with the supplied value. */
1410 /* Inputs : 1) Pointer to WID cfg structure */
1411 /* 2) Name of file containing the binary data in text mode */
1415 /* Processing : The binary data is expected to be supplied through a */
1416 /* file in text mode. This file is expected to be in the */
1417 /* finject format. It is parsed, converted to binary format */
1418 /* and copied into g_cfg_pkt for further processing. This */
1419 /* is obviously a round-about way of processing involving */
1420 /* multiple (re)conversions between bin & ascii formats. */
1421 /* But it is done nevertheless to retain uniformity and for */
1422 /* ease of debugging. */
1424 /* Outputs : None */
1426 /* Returns : None */
1431 /* Revision History: */
1433 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1434 /* 08 01 2008 Ittiam Draft */
1436 /*****************************************************************************/
1438 void ProcessBinWid(char *pcPacket
, s32
*ps32PktLen
,
1439 tstrWID
*pstrWID
, u8
*pu8val
, s32 s32ValueSize
)
1441 /* WILC_ERROR("processing Binary WIDs is not supported\n"); */
1445 s32 s32PktLen
= *ps32PktLen
;
1448 if (pstrWID
== NULL
) {
1449 PRINT_WRN(CORECONFIG_DBG
, "Can't set BIN val, NULL structure\n");
1454 pcPacket
[s32PktLen
++] = (u8
)(pstrWID
->u16WIDid
& 0xFF);
1455 pcPacket
[s32PktLen
++] = (u8
)((pstrWID
->u16WIDid
>> 8) & 0xFF);
1457 if (g_oper_mode
== SET_CFG
) {
1458 /* Message Length */
1459 u16MsgLen
= (u16
)s32ValueSize
;
1462 /* pcPacket[s32PktLen++] = (u8)u16MsgLen; */
1463 pcPacket
[s32PktLen
++] = (u8
)(u16MsgLen
& 0xFF);
1464 pcPacket
[s32PktLen
++] = (u8
)((u16MsgLen
>> 8) & 0xFF);
1467 for (idx
= 0; idx
< u16MsgLen
; idx
++)
1468 pcPacket
[s32PktLen
++] = pu8val
[idx
];
1471 for (idx
= 0; idx
< u16MsgLen
; idx
++)
1472 u8checksum
+= pcPacket
[MSG_HEADER_LEN
+ idx
+ 4];
1474 pcPacket
[s32PktLen
++] = u8checksum
;
1476 *ps32PktLen
= s32PktLen
;
1480 /*****************************************************************************/
1482 /* Function Name : further_process_response */
1484 /* Description : This function parses the response frame got from the */
1487 /* Inputs : 1) The received response frame */
1490 /* 4) Output file handle */
1491 /* 5) Process Wid Number(i.e wid from --widn switch) */
1492 /* 6) Index the array in the Global Wid Structure. */
1494 /* Globals : g_wid_num, gastrWIDs */
1496 /* Processing : This function parses the response of the device depending*/
1497 /* WID type and writes it to the output file in Hex or */
1498 /* decimal notation depending on the --getx or --get switch.*/
1500 /* Outputs : None */
1502 /* Returns : 0 on Success & -2 on Failure */
1506 /* Revision History: */
1508 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1509 /* 08 01 2009 Ittiam Draft */
1511 /*****************************************************************************/
1513 s32
further_process_response(u8
*resp
,
1516 bool process_wid_num
,
1518 tstrWID
*pstrWIDresult
)
1525 u8 cfg_str
[256] = {0};
1526 tenuWIDtype enuWIDtype
= WID_UNDEF
;
1528 if (process_wid_num
)
1529 enuWIDtype
= get_wid_type(g_wid_num
);
1531 enuWIDtype
= gastrWIDs
[cnt
].enuWIDtype
;
1534 switch (enuWIDtype
) {
1536 cfg_chr
= resp
[idx
];
1537 /*Set local copy of WID*/
1538 *(pstrWIDresult
->ps8WidVal
) = cfg_chr
;
1543 u16
*pu16val
= (u16
*)(pstrWIDresult
->ps8WidVal
);
1544 cfg_sht
= MAKE_WORD16(resp
[idx
], resp
[idx
+ 1]);
1545 /*Set local copy of WID*/
1546 /* pstrWIDresult->ps8WidVal = (s8*)(s32)cfg_sht; */
1553 u32
*pu32val
= (u32
*)(pstrWIDresult
->ps8WidVal
);
1554 cfg_int
= MAKE_WORD32(
1555 MAKE_WORD16(resp
[idx
], resp
[idx
+ 1]),
1556 MAKE_WORD16(resp
[idx
+ 2], resp
[idx
+ 3])
1558 /*Set local copy of WID*/
1559 /* pstrWIDresult->ps8WidVal = (s8*)cfg_int; */
1565 memcpy(cfg_str
, resp
+ idx
, cfg_len
);
1566 /* cfg_str[cfg_len] = '\0'; //mostafa: no need currently for NULL termination */
1567 if (pstrWIDresult
->s32ValueSize
>= cfg_len
) {
1568 memcpy(pstrWIDresult
->ps8WidVal
, cfg_str
, cfg_len
); /* mostafa: no need currently for the extra NULL byte */
1569 pstrWIDresult
->s32ValueSize
= cfg_len
;
1571 PRINT_ER("allocated WID buffer length is smaller than the received WID Length\n");
1578 create_mac_addr(cfg_str
, resp
+ idx
);
1580 strncpy(pstrWIDresult
->ps8WidVal
, cfg_str
, strlen(cfg_str
));
1581 pstrWIDresult
->ps8WidVal
[strlen(cfg_str
)] = '\0';
1585 cfg_int
= MAKE_WORD32(
1586 MAKE_WORD16(resp
[idx
], resp
[idx
+ 1]),
1587 MAKE_WORD16(resp
[idx
+ 2], resp
[idx
+ 3])
1589 conv_int_to_ip(cfg_str
, cfg_int
);
1593 if (pstrWIDresult
->s32ValueSize
>= cfg_len
) {
1594 memcpy(pstrWIDresult
->ps8WidVal
, resp
+ idx
, cfg_len
);
1595 pstrWIDresult
->s32ValueSize
= cfg_len
;
1597 PRINT_ER("Allocated WID buffer length is smaller than the received WID Length Err(%d)\n", retval
);
1603 PRINT_ER("ERROR: Check config database: Error(%d)\n", retval
);
1611 /*****************************************************************************/
1613 /* Function Name : ParseResponse */
1615 /* Description : This function parses the command-line options and */
1616 /* creates the config packets which can be sent to the WLAN */
1619 /* Inputs : 1) The received response frame */
1621 /* Globals : g_opt_list, gastrWIDs */
1623 /* Processing : This function parses the options and creates different */
1624 /* types of packets depending upon the WID-type */
1625 /* corresponding to the option. */
1627 /* Outputs : None */
1629 /* Returns : 0 on Success & -1 on Failure */
1633 /* Revision History: */
1635 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1636 /* 08 01 2008 Ittiam Draft */
1638 /*****************************************************************************/
1640 s32
ParseResponse(u8
*resp
, tstrWID
*pstrWIDcfgResult
)
1645 tenuWIDtype enuWIDtype
= WID_UNDEF
;
1646 bool num_wid_processed
= false;
1650 /* Check whether the received frame is a valid response */
1651 if (RESP_MSG_TYPE
!= resp
[0]) {
1652 PRINT_INFO(CORECONFIG_DBG
, "Received Message format incorrect.\n");
1656 /* Extract Response Length */
1657 u16RespLen
= MAKE_WORD16(resp
[2], resp
[3]);
1658 Res_Len
= u16RespLen
;
1660 for (idx
= MSG_HEADER_LEN
; idx
< u16RespLen
; ) {
1661 u16WIDid
= MAKE_WORD16(resp
[idx
], resp
[idx
+ 1]);
1662 cfg_len
= resp
[idx
+ 2];
1663 /* Incase of Bin Type Wid, the length is given by two byte field */
1664 enuWIDtype
= get_wid_type(u16WIDid
);
1665 if (WID_BIN_DATA
== enuWIDtype
) {
1666 cfg_len
|= ((u16
)resp
[idx
+ 3] << 8) & 0xFF00;
1670 if ((u16WIDid
== g_wid_num
) && (!num_wid_processed
)) {
1671 num_wid_processed
= true;
1673 if (-2 == further_process_response(&resp
[idx
], u16WIDid
, cfg_len
, true, 0, &pstrWIDcfgResult
[ResCnt
])) {
1678 for (cnt
= 0; cnt
< g_num_total_switches
; cnt
++) {
1679 if (gastrWIDs
[cnt
].u16WIDid
== u16WIDid
) {
1680 if (-2 == further_process_response(&resp
[idx
], u16WIDid
, cfg_len
, false, cnt
,
1681 &pstrWIDcfgResult
[ResCnt
])) {
1689 /* In case if BIN type Wid, The last byte of the Cfg packet is the */
1690 /* Checksum. The WID Length field does not accounts for the checksum. */
1691 /* The Checksum is discarded. */
1692 if (WID_BIN_DATA
== enuWIDtype
) {
1701 * @brief parses the write response [just detects its status: success or failure]
1703 * @param[in] pu8RespBuffer The Response to be parsed
1704 * @return Error code indicating Write Operation status:
1705 * WRITE_RESP_SUCCESS (1) => Write Success.
1706 * WILC_FAIL (-100) => Write Failure.
1713 s32
ParseWriteResponse(u8
*pu8RespBuffer
)
1715 s32 s32Error
= WILC_FAIL
;
1716 u16 u16WIDtype
= (u16
)WID_NIL
;
1718 /* Check whether the received frame is a valid response */
1719 if (RESP_MSG_TYPE
!= pu8RespBuffer
[0]) {
1720 PRINT_ER("Received Message format incorrect.\n");
1724 u16WIDtype
= MAKE_WORD16(pu8RespBuffer
[4], pu8RespBuffer
[5]);
1726 /* Check for WID_STATUS ID and then check the length and status value */
1727 if ((u16WIDtype
== WID_STATUS
) &&
1728 (pu8RespBuffer
[6] == 1) &&
1729 (pu8RespBuffer
[7] == WRITE_RESP_SUCCESS
)) {
1730 s32Error
= WRITE_RESP_SUCCESS
;
1734 /* If the length or status are not as expected return failure */
1735 s32Error
= WILC_FAIL
;
1741 * @brief creates the header of the Configuration Packet
1743 * @param[in,out] pcpacket The Configuration Packet
1744 * @param[in,out] ps32PacketLength Length of the Configuration Packet
1745 * @return Error code indicating success/failure
1752 s32
CreatePacketHeader(char *pcpacket
, s32
*ps32PacketLength
)
1754 s32 s32Error
= WILC_SUCCESS
;
1755 u16 u16MsgLen
= (u16
)(*ps32PacketLength
);
1758 /* The format of the message is: */
1759 /* +-------------------------------------------------------------------+ */
1760 /* | Message Type | Message ID | Message Length |Message body | */
1761 /* +-------------------------------------------------------------------+ */
1762 /* | 1 Byte | 1 Byte | 2 Bytes | Message Length - 4 | */
1763 /* +-------------------------------------------------------------------+ */
1765 /* The format of a message body of a message type 'W' is: */
1766 /* +-------------------------------------------------------------------+ */
1767 /* | WID0 | WID0 Length | WID0 Value | ......................... | */
1768 /* +-------------------------------------------------------------------+ */
1769 /* | 2 Bytes | 1 Byte | WID0 Length | ......................... | */
1770 /* +-------------------------------------------------------------------+ */
1775 if (g_oper_mode
== SET_CFG
)
1776 pcpacket
[u16MsgInd
++] = WRITE_MSG_TYPE
;
1778 pcpacket
[u16MsgInd
++] = QUERY_MSG_TYPE
;
1780 /* Sequence Number */
1781 pcpacket
[u16MsgInd
++] = g_seqno
++;
1783 /* Message Length */
1784 pcpacket
[u16MsgInd
++] = (u8
)(u16MsgLen
& 0xFF);
1785 pcpacket
[u16MsgInd
++] = (u8
)((u16MsgLen
>> 8) & 0xFF);
1787 *ps32PacketLength
= u16MsgLen
;
1793 * @brief creates Configuration packet based on the Input WIDs
1795 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
1796 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
1797 * @param[out] ps8packet The created Configuration Packet
1798 * @param[out] ps32PacketLength Length of the created Configuration Packet
1799 * @return Error code indicating success/failure
1806 s32
CreateConfigPacket(s8
*ps8packet
, s32
*ps32PacketLength
,
1807 tstrWID
*pstrWIDs
, u32 u32WIDsCount
)
1809 s32 s32Error
= WILC_SUCCESS
;
1811 *ps32PacketLength
= MSG_HEADER_LEN
;
1812 for (u32idx
= 0; u32idx
< u32WIDsCount
; u32idx
++) {
1813 switch (pstrWIDs
[u32idx
].enuWIDtype
) {
1815 ProcessCharWid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1816 pstrWIDs
[u32idx
].ps8WidVal
);
1820 ProcessShortWid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1821 pstrWIDs
[u32idx
].ps8WidVal
);
1825 ProcessIntWid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1826 pstrWIDs
[u32idx
].ps8WidVal
);
1830 ProcessStrWid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1831 pstrWIDs
[u32idx
].ps8WidVal
, pstrWIDs
[u32idx
].s32ValueSize
);
1835 ProcessIPwid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1836 pstrWIDs
[u32idx
].ps8WidVal
);
1840 ProcessBinWid(ps8packet
, ps32PacketLength
, &pstrWIDs
[u32idx
],
1841 pstrWIDs
[u32idx
].ps8WidVal
, pstrWIDs
[u32idx
].s32ValueSize
);
1845 PRINT_ER("ERROR: Check Config database\n");
1849 CreatePacketHeader(ps8packet
, ps32PacketLength
);
1854 s32
ConfigWaitResponse(char *pcRespBuffer
, s32 s32MaxRespBuffLen
, s32
*ps32BytesRead
,
1857 s32 s32Error
= WILC_SUCCESS
;
1859 /*removed to caller function*/
1860 /*gstrConfigPktInfo.pcRespBuffer = pcRespBuffer;
1861 * gstrConfigPktInfo.s32MaxRespBuffLen = s32MaxRespBuffLen;
1862 * gstrConfigPktInfo.bRespRequired = bRespRequired;*/
1865 if (gstrConfigPktInfo
.bRespRequired
) {
1866 down(&SemHandlePktResp
);
1868 *ps32BytesRead
= gstrConfigPktInfo
.s32BytesRead
;
1871 memset((void *)(&gstrConfigPktInfo
), 0, sizeof(tstrConfigPktInfo
));
1876 s32
ConfigProvideResponse(char *pcRespBuffer
, s32 s32RespLen
)
1878 s32 s32Error
= WILC_SUCCESS
;
1880 if (gstrConfigPktInfo
.bRespRequired
) {
1881 if (s32RespLen
<= gstrConfigPktInfo
.s32MaxRespBuffLen
) {
1882 memcpy(gstrConfigPktInfo
.pcRespBuffer
, pcRespBuffer
, s32RespLen
);
1883 gstrConfigPktInfo
.s32BytesRead
= s32RespLen
;
1885 memcpy(gstrConfigPktInfo
.pcRespBuffer
, pcRespBuffer
, gstrConfigPktInfo
.s32MaxRespBuffLen
);
1886 gstrConfigPktInfo
.s32BytesRead
= gstrConfigPktInfo
.s32MaxRespBuffLen
;
1887 PRINT_ER("BusProvideResponse() Response greater than the prepared Buffer Size\n");
1890 up(&SemHandlePktResp
);
1897 * @brief writes the received packet pu8RxPacket in the global Rx FIFO buffer
1899 * @param[in] pu8RxPacket The received packet
1900 * @param[in] s32RxPacketLen Length of the received packet
1901 * @return Error code indicating success/failure
1909 s32
ConfigPktReceived(u8
*pu8RxPacket
, s32 s32RxPacketLen
)
1911 s32 s32Error
= WILC_SUCCESS
;
1914 u8MsgType
= pu8RxPacket
[0];
1916 switch (u8MsgType
) {
1918 ConfigProvideResponse(pu8RxPacket
, s32RxPacketLen
);
1923 PRINT_INFO(CORECONFIG_DBG
, "NetworkInfo packet received\n");
1924 NetworkInfoReceived(pu8RxPacket
, s32RxPacketLen
);
1928 GnrlAsyncInfoReceived(pu8RxPacket
, s32RxPacketLen
);
1932 host_int_ScanCompleteReceived(pu8RxPacket
, s32RxPacketLen
);
1936 PRINT_ER("ConfigPktReceived(): invalid received msg type at the Core Configurator\n");
1944 * @brief Deinitializes the Core Configurator
1946 * @return Error code indicating success/failure
1953 s32
CoreConfiguratorDeInit(void)
1955 s32 s32Error
= WILC_SUCCESS
;
1957 PRINT_D(CORECONFIG_DBG
, "CoreConfiguratorDeInit()\n");
1959 if (gps8ConfigPacket
!= NULL
) {
1961 kfree(gps8ConfigPacket
);
1962 gps8ConfigPacket
= NULL
;
1968 /*Using the global handle of the driver*/
1969 extern wilc_wlan_oup_t
*gpstrWlanOps
;
1971 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
1972 * using driver config layer
1975 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
1976 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
1977 * @param[out] pu8RxResp The received Packet Response
1978 * @param[out] ps32RxRespLen Length of the received Packet Response
1979 * @return Error code indicating success/failure
1985 s32
SendConfigPkt(u8 u8Mode
, tstrWID
*pstrWIDs
,
1986 u32 u32WIDsCount
, bool bRespRequired
, u32 drvHandler
)
1988 s32 counter
= 0, ret
= 0;
1989 if (gpstrWlanOps
== NULL
) {
1990 PRINT_D(CORECONFIG_DBG
, "Net Dev is still not initialized\n");
1993 PRINT_D(CORECONFIG_DBG
, "Net Dev is initialized\n");
1995 if (gpstrWlanOps
->wlan_cfg_set
== NULL
||
1996 gpstrWlanOps
->wlan_cfg_get
== NULL
) {
1997 PRINT_D(CORECONFIG_DBG
, "Set and Get is still not initialized\n");
2000 PRINT_D(CORECONFIG_DBG
, "SET is initialized\n");
2002 if (u8Mode
== GET_CFG
) {
2003 for (counter
= 0; counter
< u32WIDsCount
; counter
++) {
2004 PRINT_INFO(CORECONFIG_DBG
, "Sending CFG packet [%d][%d]\n", !counter
,
2005 (counter
== u32WIDsCount
- 1));
2006 if (!gpstrWlanOps
->wlan_cfg_get(!counter
,
2007 pstrWIDs
[counter
].u16WIDid
,
2008 (counter
== u32WIDsCount
- 1), drvHandler
)) {
2010 printk("[Sendconfigpkt]Get Timed out\n");
2018 for (counter
= 0; counter
< u32WIDsCount
; counter
++) {
2019 pstrWIDs
[counter
].s32ValueSize
= gpstrWlanOps
->wlan_cfg_get_value(
2020 pstrWIDs
[counter
].u16WIDid
,
2021 pstrWIDs
[counter
].ps8WidVal
, pstrWIDs
[counter
].s32ValueSize
);
2024 } else if (u8Mode
== SET_CFG
) {
2025 for (counter
= 0; counter
< u32WIDsCount
; counter
++) {
2026 PRINT_D(CORECONFIG_DBG
, "Sending config SET PACKET WID:%x\n", pstrWIDs
[counter
].u16WIDid
);
2027 if (!gpstrWlanOps
->wlan_cfg_set(!counter
,
2028 pstrWIDs
[counter
].u16WIDid
, pstrWIDs
[counter
].ps8WidVal
,
2029 pstrWIDs
[counter
].s32ValueSize
,
2030 (counter
== u32WIDsCount
- 1), drvHandler
)) {
2032 printk("[Sendconfigpkt]Set Timed out\n");