| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /****************************************************************************** |
| 2 | |||
| 3 | MRF24WB0M Driver Event Handler |
||
| 4 | Module for Microchip TCP/IP Stack |
||
| 5 | -Provides access to MRF24WB0M WiFi controller |
||
| 6 | -Reference: MRF24WB0M Data sheet, IEEE 802.11 Standard |
||
| 7 | |||
| 8 | ******************************************************************************* |
||
| 9 | FileName: WFEventHandler.c |
||
| 10 | Dependencies: TCP/IP Stack header files |
||
| 11 | Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 |
||
| 12 | Compiler: Microchip C32 v1.10b or higher |
||
| 13 | Microchip C30 v3.22 or higher |
||
| 14 | Microchip C18 v3.34 or higher |
||
| 15 | Company: Microchip Technology, Inc. |
||
| 16 | |||
| 17 | Software License Agreement |
||
| 18 | |||
| 19 | Copyright (C) 2002-2010 Microchip Technology Inc. All rights reserved. |
||
| 20 | |||
| 21 | Microchip licenses to you the right to use, modify, copy, and distribute: |
||
| 22 | (i) the Software when embedded on a Microchip microcontroller or digital |
||
| 23 | signal controller product ("Device") which is integrated into |
||
| 24 | Licensee's product; or |
||
| 25 | (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
| 26 | ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device used in |
||
| 27 | conjunction with a Microchip ethernet controller for the sole purpose |
||
| 28 | of interfacing with the ethernet controller. |
||
| 29 | |||
| 30 | You should refer to the license agreement accompanying this Software for |
||
| 31 | additional information regarding your rights and obligations. |
||
| 32 | |||
| 33 | THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY |
||
| 34 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
| 35 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
||
| 36 | NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL, |
||
| 37 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST |
||
| 38 | OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS BY |
||
| 39 | THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS |
||
| 40 | FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON |
||
| 41 | THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR |
||
| 42 | OTHERWISE. |
||
| 43 | |||
| 44 | |||
| 45 | Author Date Comment |
||
| 46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 47 | KH 27 Jan 2010 Created for MRF24WB0M |
||
| 48 | ******************************************************************************/ |
||
| 49 | |||
| 50 | /*==========================================================================*/ |
||
| 51 | /* INCLUDES */ |
||
| 52 | /*==========================================================================*/ |
||
| 53 | #include "TCPIP Stack/WFMac.h" |
||
| 54 | #if defined(WF_CS_TRIS) |
||
| 55 | |||
| 56 | |||
| 57 | /*==========================================================================*/ |
||
| 58 | /* DEFINES */ |
||
| 59 | /*==========================================================================*/ |
||
| 60 | /* used for assertions */ |
||
| 61 | #ifdef WF_DEBUG |
||
| 62 | #define WF_MODULE_NUMBER WF_MODULE_EVENT_HANDLER |
||
| 63 | #endif |
||
| 64 | |||
| 65 | /*-------------------------------------------*/ |
||
| 66 | /* Connection Manager Event Message Subtypes */ |
||
| 67 | /* (Used in Mgmt Indicate messages) */ |
||
| 68 | /*-------------------------------------------*/ |
||
| 69 | #define WF_EVENT_CONNECTION_ATTEMPT_STATUS_SUBTYPE (6) |
||
| 70 | #define WF_EVENT_CONNECTION_LOST_SUBTYPE (7) |
||
| 71 | #define WF_EVENT_CONNECTION_REESTABLISHED_SUBTYPE (8) |
||
| 72 | #define WF_EVENT_KEY_CALCULATION_COMPLETE_SUBTYPE (9) |
||
| 73 | #define WF_EVENT_FLASH_UPDATE_STATUS_SUBTYPE (10) |
||
| 74 | #define WF_EVENT_SCAN_RESULTS_READY_SUBTYPE (11) |
||
| 75 | #define WF_EVENT_SCAN_IE_RESULTS_READY_SUBTYPE (12) |
||
| 76 | |||
| 77 | /* event values for index 2 of WF_CONNECTION_ATTEMPT_STATUS_EVENT_SUBTYPE */ |
||
| 78 | #define CONNECTION_ATTEMPT_SUCCESSFUL ((UINT8)1) /* if not 1 then failed to connect and info field is error code */ |
||
| 79 | #define CONNECTION_ATTEMPT_FAILED ((UINT8)2) |
||
| 80 | |||
| 81 | /* event values for index 2 of WF_EVENT_CONNECTION_LOST_SUBTYPE */ |
||
| 82 | #define CONNECTION_TEMPORARILY_LOST ((UINT8)1) |
||
| 83 | #define CONNECTION_PERMANENTLY_LOST ((UINT8)2) |
||
| 84 | #define CONNECTION_REESTABLISHED ((UINT8)3) |
||
| 85 | |||
| 86 | /* event values for index 2 of WF_EVENT_FLASH_UPDATE_STATUS_SUBTYPE */ |
||
| 87 | #define FLASH_UPDATE_SUCCESSFUL ((UINT8)1) |
||
| 88 | #define FLASH_UPDATE_FAILED ((UINT8)2) |
||
| 89 | |||
| 90 | |||
| 91 | /*==========================================================================*/ |
||
| 92 | /* LOCAL FUNCTIONS */ |
||
| 93 | /*==========================================================================*/ |
||
| 94 | static BOOL isNotifyApp(UINT8 event); |
||
| 95 | static BOOL isEventNotifyBitSet(UINT8 notifyMask, UINT8 notifyBit); |
||
| 96 | |||
| 97 | /***************************************************************************** |
||
| 98 | * FUNCTION: WFProcessMgmtIndicateMsg |
||
| 99 | * |
||
| 100 | * RETURNS: error code |
||
| 101 | * |
||
| 102 | * PARAMS: None |
||
| 103 | * |
||
| 104 | * NOTES: Processes a management indicate message |
||
| 105 | *****************************************************************************/ |
||
| 106 | void WFProcessMgmtIndicateMsg() |
||
| 107 | { |
||
| 108 | tMgmtIndicateHdr hdr; |
||
| 109 | UINT8 buf[6]; |
||
| 110 | UINT8 event = 0xff; |
||
| 111 | UINT16 eventInfo; |
||
| 112 | |||
| 113 | /* read 2-byte header of management message */ |
||
| 114 | RawRead(RAW_RX_ID, 0, sizeof(tMgmtIndicateHdr), (UINT8 *)&hdr); |
||
| 115 | |||
| 116 | /* Determine which event occurred and handle it */ |
||
| 117 | switch (hdr.subType) |
||
| 118 | { |
||
| 119 | /*-----------------------------------------------------------------*/ |
||
| 120 | case WF_EVENT_CONNECTION_ATTEMPT_STATUS_SUBTYPE: |
||
| 121 | /*-----------------------------------------------------------------*/ |
||
| 122 | /* There is one data byte with this message */ |
||
| 123 | RawRead(RAW_RX_ID, sizeof(tMgmtIndicateHdr), 1, buf); /* read first byte after header */ |
||
| 124 | /* if connection attempt successful */ |
||
| 125 | if (buf[0] == CONNECTION_ATTEMPT_SUCCESSFUL) |
||
| 126 | { |
||
| 127 | event = WF_EVENT_CONNECTION_SUCCESSFUL; |
||
| 128 | eventInfo = WF_NO_ADDITIONAL_INFO; |
||
| 129 | SetLogicalConnectionState(TRUE); |
||
| 130 | } |
||
| 131 | /* else connection attempt failed */ |
||
| 132 | else |
||
| 133 | { |
||
| 134 | event = WF_EVENT_CONNECTION_FAILED; |
||
| 135 | eventInfo = (UINT16)buf[0]; /* contains connection failure code */ |
||
| 136 | SetLogicalConnectionState(FALSE); |
||
| 137 | } |
||
| 138 | break; |
||
| 139 | |||
| 140 | /*-----------------------------------------------------------------*/ |
||
| 141 | case WF_EVENT_CONNECTION_LOST_SUBTYPE: |
||
| 142 | /*-----------------------------------------------------------------*/ |
||
| 143 | /* read index 2 and 3 from message and store in buf[0] and buf[1] |
||
| 144 | buf[0] -- 1: Connection temporarily lost 2: Connection permanently lost 3: Connection Reestablished |
||
| 145 | buf[1] -- 0: Beacon Timeout 1: Deauth from AP */ |
||
| 146 | RawRead(RAW_RX_ID, sizeof(tMgmtIndicateHdr), 2, buf); |
||
| 147 | |||
| 148 | if (buf[0] == CONNECTION_TEMPORARILY_LOST) |
||
| 149 | { |
||
| 150 | event = WF_EVENT_CONNECTION_TEMPORARILY_LOST; |
||
| 151 | eventInfo = (UINT16)buf[1]; /* lost due to beacon timeout or deauth */ |
||
| 152 | } |
||
| 153 | else if (buf[0] == CONNECTION_PERMANENTLY_LOST) |
||
| 154 | { |
||
| 155 | event = WF_EVENT_CONNECTION_PERMANENTLY_LOST; |
||
| 156 | eventInfo = (UINT16)buf[1]; /* lost due to beacon timeout or deauth */ |
||
| 157 | SetLogicalConnectionState(FALSE); |
||
| 158 | } |
||
| 159 | else if (buf[0] == CONNECTION_REESTABLISHED) |
||
| 160 | { |
||
| 161 | event = WF_EVENT_CONNECTION_REESTABLISHED; |
||
| 162 | eventInfo = (UINT16)buf[1]; /* originally lost due to beacon timeout or deauth */ |
||
| 163 | } |
||
| 164 | else |
||
| 165 | { |
||
| 166 | /* invalid parameter in message */ |
||
| 167 | WF_ASSERT(FALSE); |
||
| 168 | } |
||
| 169 | break; |
||
| 170 | |||
| 171 | /*-----------------------------------------------------------------*/ |
||
| 172 | case WF_EVENT_FLASH_UPDATE_STATUS_SUBTYPE: |
||
| 173 | /*-----------------------------------------------------------------*/ |
||
| 174 | /* read index 2 of mgmt indicate to get flash update status */ |
||
| 175 | RawRead(RAW_RX_ID, sizeof(tMgmtIndicateHdr), 1, buf); |
||
| 176 | if (buf[0] == FLASH_UPDATE_SUCCESSFUL) |
||
| 177 | { |
||
| 178 | event = WF_EVENT_FLASH_UPDATE_SUCCESSFUL; |
||
| 179 | } |
||
| 180 | else if (buf[0] == FLASH_UPDATE_FAILED) |
||
| 181 | { |
||
| 182 | event = WF_EVENT_FLASH_UPDATE_FAILED; |
||
| 183 | } |
||
| 184 | eventInfo = WF_NO_ADDITIONAL_INFO; |
||
| 185 | break; |
||
| 186 | |||
| 187 | /*-----------------------------------------------------------------*/ |
||
| 188 | case WF_EVENT_SCAN_RESULTS_READY_SUBTYPE: |
||
| 189 | /*-----------------------------------------------------------------*/ |
||
| 190 | /* read index 2 of mgmt indicate to get the number of scan results */ |
||
| 191 | RawRead(RAW_RX_ID, sizeof(tMgmtIndicateHdr), 1, buf); |
||
| 192 | event = WF_EVENT_SCAN_RESULTS_READY; |
||
| 193 | eventInfo = (UINT16)buf[0]; /* number of scan results */ |
||
| 194 | break; |
||
| 195 | |||
| 196 | /*-----------------------------------------------------------------*/ |
||
| 197 | case WF_EVENT_SCAN_IE_RESULTS_READY_SUBTYPE: |
||
| 198 | /*-----------------------------------------------------------------*/ |
||
| 199 | event = WF_EVENT_IE_RESULTS_READY; |
||
| 200 | /* read indexes 2 and 3 containing the 16-bit value of IE bytes */ |
||
| 201 | RawRead(RAW_RX_ID, sizeof(tMgmtIndicateHdr), 2, (UINT8 *)&eventInfo); |
||
| 202 | eventInfo = WFSTOHS(eventInfo); /* fix endianess of 16-bit value */ |
||
| 203 | break; |
||
| 204 | |||
| 205 | /*-----------------------------------------------------------------*/ |
||
| 206 | default: |
||
| 207 | /*-----------------------------------------------------------------*/ |
||
| 208 | WF_ASSERT(FALSE); |
||
| 209 | break; |
||
| 210 | } |
||
| 211 | |||
| 212 | /* free mgmt buffer */ |
||
| 213 | DeallocateMgmtRxBuffer(); |
||
| 214 | |||
| 215 | /* if the application wants to be notified of the event */ |
||
| 216 | if (isNotifyApp(event)) |
||
| 217 | { |
||
| 218 | WF_ProcessEvent(event, eventInfo); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | |||
| 223 | /***************************************************************************** |
||
| 224 | * FUNCTION: isEventNotifyBitSet |
||
| 225 | * |
||
| 226 | * RETURNS: TRUE if the notify bit is set in the notify mask. |
||
| 227 | * |
||
| 228 | * PARAMS: notifyMask -- the bit mask of events the application wishes to be |
||
| 229 | * notified of |
||
| 230 | * notifyBit -- the specific event that occurred |
||
| 231 | * |
||
| 232 | * NOTES: Determines if the input event it enabled in the notify mask |
||
| 233 | *****************************************************************************/ |
||
| 234 | static BOOL isEventNotifyBitSet(UINT8 notifyMask, UINT8 notifyBit) |
||
| 235 | { |
||
| 236 | /* check if the event notify bit is set */ |
||
| 237 | return ((notifyMask & notifyBit) > 0); |
||
| 238 | } |
||
| 239 | |||
| 240 | /***************************************************************************** |
||
| 241 | * FUNCTION: isNotifyApp |
||
| 242 | * |
||
| 243 | * RETURNS: TRUE if application wants to be notified of event, else FALSE |
||
| 244 | * |
||
| 245 | * PARAMS: event -- the event that occurred |
||
| 246 | * |
||
| 247 | * NOTES: Determines if the input event is one which the application should be |
||
| 248 | * notified of. |
||
| 249 | *****************************************************************************/ |
||
| 250 | static BOOL isNotifyApp(UINT8 event) |
||
| 251 | { |
||
| 252 | BOOL notify = FALSE; |
||
| 253 | UINT8 notifyMask = GetEventNotificationMask(); |
||
| 254 | |||
| 255 | /* determine if user wants to be notified of event */ |
||
| 256 | switch (event) |
||
| 257 | { |
||
| 258 | case WF_EVENT_CONNECTION_SUCCESSFUL: |
||
| 259 | if (isEventNotifyBitSet(notifyMask, WF_NOTIFY_CONNECTION_ATTEMPT_SUCCESSFUL)) |
||
| 260 | { |
||
| 261 | notify = TRUE; |
||
| 262 | } |
||
| 263 | break; |
||
| 264 | |||
| 265 | case WF_EVENT_CONNECTION_FAILED: |
||
| 266 | if (isEventNotifyBitSet(notifyMask, WF_NOTIFY_CONNECTION_ATTEMPT_FAILED)) |
||
| 267 | { |
||
| 268 | notify = TRUE; |
||
| 269 | } |
||
| 270 | break; |
||
| 271 | |||
| 272 | case WF_EVENT_CONNECTION_TEMPORARILY_LOST: |
||
| 273 | if (isEventNotifyBitSet(notifyMask, WF_NOTIFY_CONNECTION_TEMPORARILY_LOST)) |
||
| 274 | { |
||
| 275 | notify = TRUE; |
||
| 276 | } |
||
| 277 | break; |
||
| 278 | |||
| 279 | case WF_EVENT_CONNECTION_PERMANENTLY_LOST: |
||
| 280 | if (isEventNotifyBitSet(notifyMask, WF_NOTIFY_CONNECTION_PERMANENTLY_LOST)) |
||
| 281 | { |
||
| 282 | notify = TRUE; |
||
| 283 | } |
||
| 284 | break; |
||
| 285 | |||
| 286 | case WF_EVENT_CONNECTION_REESTABLISHED: |
||
| 287 | if (isEventNotifyBitSet(notifyMask, WF_NOTIFY_CONNECTION_PERMANENTLY_LOST)) |
||
| 288 | { |
||
| 289 | notify = TRUE; |
||
| 290 | } |
||
| 291 | break; |
||
| 292 | |||
| 293 | default: |
||
| 294 | notify = TRUE; /* the app gets notified of all other events */ |
||
| 295 | break; |
||
| 296 | } |
||
| 297 | |||
| 298 | return notify; |
||
| 299 | |||
| 300 | } |
||
| 301 | |||
| 302 | |||
| 303 | |||
| 304 | #endif /* WF_CS_TRIS */ |
||
| 305 | |||
| 306 |
Powered by WebSVN v2.8.3