3 * @file coreconfigurator.c
6 * @sa coreconfigurator.h
11 #include "coreconfigurator.h"
12 #include "wilc_wlan_if.h"
13 #include "wilc_wlan.h"
14 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/etherdevice.h>
17 #define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
18 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
23 /* Basic Frame Type Codes (2-bit) */
24 enum basic_frame_type {
25 FRAME_TYPE_CONTROL = 0x04,
26 FRAME_TYPE_DATA = 0x08,
27 FRAME_TYPE_MANAGEMENT = 0x00,
28 FRAME_TYPE_RESERVED = 0x0C,
29 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
32 /* Frame Type and Subtype Codes (6-bit) */
63 QOS_DATA_POLL_ACK = 0xB8,
64 QOS_NULL_FRAME = 0xC8,
66 QOS_CFPOLL_ACK = 0xF8,
69 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
72 /* Element ID of various Information Elements */
73 enum info_element_id {
74 ISSID = 0, /* Service Set Identifier */
75 ISUPRATES = 1, /* Supported Rates */
76 IFHPARMS = 2, /* FH parameter set */
77 IDSPARMS = 3, /* DS parameter set */
78 ICFPARMS = 4, /* CF parameter set */
79 ITIM = 5, /* Traffic Information Map */
80 IIBPARMS = 6, /* IBSS parameter set */
81 ICOUNTRY = 7, /* Country element */
82 IEDCAPARAMS = 12, /* EDCA parameter set */
83 ITSPEC = 13, /* Traffic Specification */
84 ITCLAS = 14, /* Traffic Classification */
85 ISCHED = 15, /* Schedule */
86 ICTEXT = 16, /* Challenge Text */
87 IPOWERCONSTRAINT = 32, /* Power Constraint */
88 IPOWERCAPABILITY = 33, /* Power Capability */
89 ITPCREQUEST = 34, /* TPC Request */
90 ITPCREPORT = 35, /* TPC Report */
91 ISUPCHANNEL = 36, /* Supported channel list */
92 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
93 IMEASUREMENTREQUEST = 38, /* Measurement request */
94 IMEASUREMENTREPORT = 39, /* Measurement report */
95 IQUIET = 40, /* Quiet element Info */
96 IIBSSDFS = 41, /* IBSS DFS */
97 IERPINFO = 42, /* ERP Information */
98 ITSDELAY = 43, /* TS Delay */
99 ITCLASPROCESS = 44, /* TCLAS Processing */
100 IHTCAP = 45, /* HT Capabilities */
101 IQOSCAP = 46, /* QoS Capability */
102 IRSNELEMENT = 48, /* RSN Information Element */
103 IEXSUPRATES = 50, /* Extended Supported Rates */
104 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
105 IHTOPERATION = 61, /* HT Information */
106 ISECCHOFF = 62, /* Secondary Channel Offeset */
107 I2040COEX = 72, /* 20/40 Coexistence IE */
108 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
109 IOBSSSCAN = 74, /* OBSS Scan parameters */
110 IEXTCAP = 127, /* Extended capability */
111 IWMM = 221, /* WMM parameters */
112 IWPAELEMENT = 221, /* WPA Information Element */
113 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
116 /* This function extracts the beacon period field from the beacon or probe */
117 /* response frame. */
118 static inline u16 get_beacon_period(u8 *data)
123 bcn_per |= (data[1] << 8);
128 static inline u32 get_beacon_timestamp_lo(u8 *data)
131 u32 index = MAC_HDR_LEN;
133 time_stamp |= data[index++];
134 time_stamp |= (data[index++] << 8);
135 time_stamp |= (data[index++] << 16);
136 time_stamp |= (data[index] << 24);
141 static inline u32 get_beacon_timestamp_hi(u8 *data)
144 u32 index = (MAC_HDR_LEN + 4);
146 time_stamp |= data[index++];
147 time_stamp |= (data[index++] << 8);
148 time_stamp |= (data[index++] << 16);
149 time_stamp |= (data[index] << 24);
154 /* This function extracts the 'frame type and sub type' bits from the MAC */
155 /* header of the input frame. */
156 /* Returns the value in the LSB of the returned value. */
157 static inline enum sub_frame_type get_sub_type(u8 *header)
159 return ((enum sub_frame_type)(header[0] & 0xFC));
162 /* This function extracts the 'to ds' bit from the MAC header of the input */
164 /* Returns the value in the LSB of the returned value. */
165 static inline u8 get_to_ds(u8 *header)
167 return (header[1] & 0x01);
170 /* This function extracts the 'from ds' bit from the MAC header of the input */
172 /* Returns the value in the LSB of the returned value. */
173 static inline u8 get_from_ds(u8 *header)
175 return ((header[1] & 0x02) >> 1);
178 /* This function extracts the BSSID from the incoming WLAN packet based on */
179 /* the 'from ds' bit, and updates the MAC Address in the allocated 'data' */
181 static inline void get_BSSID(u8 *data, u8 *bssid)
183 if (get_from_ds(data) == 1)
185 * Extract the MAC Address in 'address2' field of the MAC
186 * header and update the MAC Address in the allocated 'data'
189 ether_addr_copy(data, bssid + ADDR2);
190 else if (get_to_ds(data) == 1)
192 * Extract the MAC Address in 'address1' field of the MAC
193 * header and update the MAC Address in the allocated 'data'
196 ether_addr_copy(data, bssid + ADDR1);
199 * Extract the MAC Address in 'address3' field of the MAC
200 * header and update the MAC Address in the allocated 'data'
203 ether_addr_copy(data, bssid + ADDR3);
206 /* This function extracts the SSID from a beacon/probe response frame */
207 static inline void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
213 len = data[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
215 j = MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
218 /* If the SSID length field is set wrongly to a value greater than the */
219 /* allowed maximum SSID length limit, reset the length to 0 */
220 if (len >= MAX_SSID_LEN)
223 for (i = 0; i < len; i++, j++)
231 /* This function extracts the capability info field from the beacon or probe */
232 /* response frame. */
233 static inline u16 get_cap_info(u8 *data)
236 u16 index = MAC_HDR_LEN;
237 enum sub_frame_type st;
239 st = get_sub_type(data);
241 /* Location of the Capability field is different for Beacon and */
242 /* Association frames. */
243 if ((st == BEACON) || (st == PROBE_RSP))
244 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
246 cap_info = data[index];
247 cap_info |= (data[index + 1] << 8);
252 /* This function extracts the capability info field from the Association */
253 /* response frame. */
254 static inline u16 get_assoc_resp_cap_info(u8 *data)
259 cap_info |= (data[1] << 8);
264 /* This function extracts the association status code from the incoming */
265 /* association response frame and returns association status code */
266 static inline u16 get_asoc_status(u8 *data)
270 asoc_status = data[3];
271 asoc_status = (asoc_status << 8) | data[2];
276 /* This function extracts association ID from the incoming association */
278 static inline u16 get_asoc_id(u8 *data)
283 asoc_id |= (data[5] << 8);
288 u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
292 /*************************************************************************/
293 /* Beacon Frame - Frame Body */
294 /* --------------------------------------------------------------------- */
295 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
296 /* --------------------------------------------------------------------- */
297 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
298 /* --------------------------------------------------------------------- */
300 /*************************************************************************/
302 u16index = u16TagParamOffset;
304 /* Search for the TIM Element Field and return if the element is found */
305 while (u16index < (u16RxLen - FCS_LEN)) {
306 if (pu8msa[u16index] == ITIM)
307 return &pu8msa[u16index];
308 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
314 /* This function gets the current channel information from
315 * the 802.11n beacon/probe response frame */
316 u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
320 index = TAG_PARAM_OFFSET;
321 while (index < (u16RxLen - FCS_LEN)) {
322 if (pu8msa[index] == IDSPARMS)
323 return pu8msa[index + 2];
324 /* Increment index by length information and header */
325 index += pu8msa[index + 1] + IE_HDR_LEN;
328 /* Return current channel information from the MIB, if beacon/probe */
329 /* response frame does not contain the DS parameter set IE */
330 /* return (mget_CurrentChannel() + 1); */
331 return 0; /* no MIB here */
335 * @brief parses the received 'N' message
337 * @param[in] pu8MsgBuffer The message to be parsed
338 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
339 * @return Error code indicating success/failure
345 s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
347 tstrNetworkInfo *pstrNetworkInfo = NULL;
352 u16 u16WidID = (u16)WID_NIL;
354 u8 *pu8WidVal = NULL;
356 u8MsgType = pu8MsgBuffer[0];
358 /* Check whether the received message type is 'N' */
359 if ('N' != u8MsgType) {
360 PRINT_ER("Received Message format incorrect.\n");
364 /* Extract message ID */
365 u8MsgID = pu8MsgBuffer[1];
367 /* Extract message Length */
368 u16MsgLen = MAKE_WORD16(pu8MsgBuffer[2], pu8MsgBuffer[3]);
371 u16WidID = MAKE_WORD16(pu8MsgBuffer[4], pu8MsgBuffer[5]);
373 /* Extract WID Length */
374 u16WidLen = MAKE_WORD16(pu8MsgBuffer[6], pu8MsgBuffer[7]);
376 /* Assign a pointer to the WID value */
377 pu8WidVal = &pu8MsgBuffer[8];
379 /* parse the WID value of the WID "WID_NEWORK_INFO" */
383 u8 *pu8TimElm = NULL;
390 pstrNetworkInfo = kzalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
391 if (!pstrNetworkInfo)
394 pstrNetworkInfo->s8rssi = pu8WidVal[0];
396 /* Assign a pointer to msa "Mac Header Start Address" */
397 pu8msa = &pu8WidVal[1];
399 u16RxLen = u16WidLen - 1;
403 /* Get the cap_info */
404 pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
405 /* Get time-stamp [Low only 32 bit] */
406 pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
407 PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
409 /* Get full time-stamp [Low and High 64 bit] */
410 u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
411 u32Tsf_Hi = get_beacon_timestamp_hi(pu8msa);
413 pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
416 get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &pstrNetworkInfo->u8SsidLen);
419 get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
422 * Extract current channel information from
423 * the beacon/probe response frame
425 pstrNetworkInfo->u8channel = get_current_channel_802_11n(pu8msa,
428 /* Get beacon period */
429 u8index = MAC_HDR_LEN + TIME_STAMP_LEN;
431 pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
433 u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
435 /* Get DTIM Period */
436 pu8TimElm = get_tim_elm(pu8msa, u16RxLen + FCS_LEN, u8index);
437 if (pu8TimElm != NULL)
438 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
439 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
440 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
443 pstrNetworkInfo->pu8IEs = kmemdup(pu8IEs, u16IEsLen,
445 if (!pstrNetworkInfo->pu8IEs)
448 pstrNetworkInfo->u16IEsLen = u16IEsLen;
452 *ppstrNetworkInfo = pstrNetworkInfo;
458 * @brief Deallocates the parsed Network Info
460 * @param[in] pstrNetworkInfo Network Info to be deallocated
461 * @return Error code indicating success/failure
467 s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
471 if (pstrNetworkInfo != NULL) {
472 if (pstrNetworkInfo->pu8IEs != NULL) {
473 kfree(pstrNetworkInfo->pu8IEs);
474 pstrNetworkInfo->pu8IEs = NULL;
479 kfree(pstrNetworkInfo);
480 pstrNetworkInfo = NULL;
490 * @brief parses the received Association Response frame
492 * @param[in] pu8Buffer The Association Response frame to be parsed
493 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
494 * @return Error code indicating success/failure
500 s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
501 tstrConnectRespInfo **ppstrConnectRespInfo)
504 tstrConnectRespInfo *pstrConnectRespInfo = NULL;
505 u16 u16AssocRespLen = 0;
509 pstrConnectRespInfo = kzalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
510 if (!pstrConnectRespInfo)
513 /* u16AssocRespLen = pu8Buffer[0]; */
514 u16AssocRespLen = (u16)u32BufferLen;
516 /* get the status code */
517 pstrConnectRespInfo->u16ConnectStatus = get_asoc_status(pu8Buffer);
518 if (pstrConnectRespInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
520 /* get the capability */
521 pstrConnectRespInfo->u16capability = get_assoc_resp_cap_info(pu8Buffer);
523 /* get the Association ID */
524 pstrConnectRespInfo->u16AssocID = get_asoc_id(pu8Buffer);
526 /* get the Information Elements */
527 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
528 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
530 pstrConnectRespInfo->pu8RespIEs = kmemdup(pu8IEs, u16IEsLen, GFP_KERNEL);
531 if (!pstrConnectRespInfo->pu8RespIEs)
534 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
537 *ppstrConnectRespInfo = pstrConnectRespInfo;
543 * @brief Deallocates the parsed Association Response Info
545 * @param[in] pstrNetworkInfo Network Info to be deallocated
546 * @return Error code indicating success/failure
552 s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
556 if (pstrConnectRespInfo != NULL) {
557 if (pstrConnectRespInfo->pu8RespIEs != NULL) {
558 kfree(pstrConnectRespInfo->pu8RespIEs);
559 pstrConnectRespInfo->pu8RespIEs = NULL;
564 kfree(pstrConnectRespInfo);
565 pstrConnectRespInfo = NULL;
575 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
576 * using driver config layer
579 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
580 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
581 * @param[out] pu8RxResp The received Packet Response
582 * @param[out] ps32RxRespLen Length of the received Packet Response
583 * @return Error code indicating success/failure
589 s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv)
591 s32 counter = 0, ret = 0;
593 if (mode == GET_CFG) {
594 for (counter = 0; counter < count; counter++) {
595 PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
596 (counter == count - 1));
597 if (!wilc_wlan_cfg_get(!counter,
599 (counter == count - 1),
602 printk("[Sendconfigpkt]Get Timed out\n");
607 for (counter = 0; counter < count; counter++) {
608 wids[counter].size = wilc_wlan_cfg_get_val(
614 } else if (mode == SET_CFG) {
615 for (counter = 0; counter < count; counter++) {
616 PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", wids[counter].id);
617 if (!wilc_wlan_cfg_set(!counter,
621 (counter == count - 1),
624 printk("[Sendconfigpkt]Set Timed out\n");