Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /****************************************************************************** |
2 | |||
3 | MRF24WB0M Driver |
||
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: WFEasyConfig.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 | Steve Collmeyer 24 Sep 2009 Initial |
||
48 | Brad Rex 09 Feb 2010 Update for RoadRunner |
||
49 | ******************************************************************************/ |
||
50 | #include "HardwareProfile.h" |
||
51 | #include "TCPIPConfig.h" |
||
52 | |||
53 | #if defined(WF_CS_TRIS) |
||
54 | |||
55 | #include <string.h> /* for memcpy */ //SCC2???? |
||
56 | |||
57 | #include "TCPIP Stack/WFEasyConfig.h" |
||
58 | #include "TCPIP Stack/WFApi.h" |
||
59 | #include "TCPIP Stack/WFConsole.h" |
||
60 | |||
61 | #if defined ( EZ_CONFIG_SCAN ) |
||
62 | tWFScanCtx g_ScanCtx; |
||
63 | #endif /* EZ_CONFIG_SCAN */ |
||
64 | |||
65 | #if defined(STACK_USE_EZ_CONFIG) |
||
66 | /* Easy Config Globals */ |
||
67 | extern UINT8 ConnectionProfileID; //SCC2 ??? what to do with this... |
||
68 | |||
69 | tWFEasyConfigCtx g_easyConfigCtx; |
||
70 | |||
71 | /* Easy Config Private Functions */ |
||
72 | static int WFEasyConfigProcess(void); |
||
73 | |||
74 | void WFEasyConfigInit() |
||
75 | { |
||
76 | CFGCXT.ssid[0] = 0; |
||
77 | CFGCXT.security = WF_SECURITY_OPEN; |
||
78 | CFGCXT.key[0] = 0; |
||
79 | CFGCXT.defaultWepKey = WF_WEP_KEY_INVALID; |
||
80 | CFGCXT.type = WF_INFRASTRUCTURE; |
||
81 | CFGCXT.cfg_state = cfg_stopped; |
||
82 | CFGCXT.isWifiNeedToConfigure = 0; |
||
83 | |||
84 | #if defined (EZ_CONFIG_STORE) |
||
85 | CFGCXT.isWifiDoneConfigure = AppConfig.dataValid; |
||
86 | #endif |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | void WFEasyConfigMgr() |
||
91 | { |
||
92 | if (CFGCXT.isWifiNeedToConfigure) { |
||
93 | if (WFEasyConfigProcess()) { |
||
94 | //Has been configured, clear flag |
||
95 | CFGCXT.isWifiNeedToConfigure = 0; |
||
96 | CFGCXT.isWifiDoneConfigure = 1; |
||
97 | } |
||
98 | } |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | static int WFEasyConfigProcess(void) |
||
103 | { |
||
104 | UINT8 ConnectionProfileID; |
||
105 | UINT8 ConnectionState; |
||
106 | |||
107 | #if defined (EZ_CONFIG_STALL) |
||
108 | if (CFGCXT.cfg_state == cfg_stopped) |
||
109 | { |
||
110 | /* State machine just started get current time stamp */ |
||
111 | CFGCXT.cfg_state = cfg_stalled; |
||
112 | CFGCXT.timeStart = TickGet(); |
||
113 | return 0; |
||
114 | } |
||
115 | |||
116 | /* Wait for stall time to expire */ |
||
117 | if (CFGCXT.cfg_state == cfg_stalled) |
||
118 | { |
||
119 | UINT32 time = TickGet(); |
||
120 | if ((time - CFGCXT.timeStart) < WF_STALL_TIME_MS) |
||
121 | return 0; |
||
122 | } |
||
123 | |||
124 | #endif //EZ_CONFIG_STALL |
||
125 | |||
126 | /* We will re-use the current profile */ |
||
127 | WF_CMGetConnectionState(&ConnectionState, &ConnectionProfileID); |
||
128 | |||
129 | /* Need to disconnect */ |
||
130 | WF_CMDisconnect(); |
||
131 | |||
132 | /* Delete profile */ |
||
133 | WF_CPDelete(ConnectionProfileID); |
||
134 | |||
135 | /* Create and prepare new profile */ |
||
136 | WF_CPCreate(&ConnectionProfileID); |
||
137 | |||
138 | /* Now set the various connection profile parameters */ |
||
139 | |||
140 | /* Set SSID... */ |
||
141 | if (CFGCXT.ssid) |
||
142 | #if defined(__18CXX) |
||
143 | WF_CPSetSsid(ConnectionProfileID, |
||
144 | (ROM char *)CFGCXT.ssid, |
||
145 | strlen(CFGCXT.ssid)); |
||
146 | #else |
||
147 | WF_CPSetSsid(ConnectionProfileID, |
||
148 | CFGCXT.ssid, |
||
149 | strlen((char*)CFGCXT.ssid)); |
||
150 | #endif |
||
151 | |||
152 | /* Now deal with security... */ |
||
153 | switch ((BYTE)CFGCXT.security) { |
||
154 | case WF_SECURITY_OPEN: /* No security */ |
||
155 | WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_OPEN, 0, 0, 0); |
||
156 | break; |
||
157 | |||
158 | case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: |
||
159 | if (CFGCXT.key) { |
||
160 | WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE, 0, CFGCXT.key, strlen((char *)CFGCXT.key)); |
||
161 | } |
||
162 | break; |
||
163 | |||
164 | case WF_SECURITY_WPA_AUTO_WITH_KEY: |
||
165 | if (CFGCXT.key) { |
||
166 | WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_KEY, 0, CFGCXT.key, 32); |
||
167 | } |
||
168 | break; |
||
169 | |||
170 | case WF_SECURITY_WEP_40: |
||
171 | { |
||
172 | BYTE keys[20]; |
||
173 | int i; |
||
174 | |||
175 | if (CFGCXT.key) { |
||
176 | /* Clear key */ |
||
177 | for (i = 0; i < 20; i++) |
||
178 | keys[i] = 0; |
||
179 | memcpy(keys, CFGCXT.key, 20); |
||
180 | WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_40, CFGCXT.defaultWepKey, keys, 20); |
||
181 | } |
||
182 | } |
||
183 | break; |
||
184 | |||
185 | case WF_SECURITY_WEP_104: |
||
186 | { |
||
187 | BYTE keys[52]; |
||
188 | int i; |
||
189 | |||
190 | if (CFGCXT.key) { |
||
191 | /* Clear key */ |
||
192 | for (i = 0; i < 52; i++) |
||
193 | keys[i] = 0; |
||
194 | memcpy(keys, CFGCXT.key, 52); |
||
195 | WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_104, CFGCXT.defaultWepKey, keys, 52); |
||
196 | } |
||
197 | } |
||
198 | break; |
||
199 | } |
||
200 | |||
201 | #if defined (EZ_CONFIG_STORE) |
||
202 | SaveWifiConfig(); |
||
203 | #endif |
||
204 | |||
205 | /* Set wlan mode */ |
||
206 | WF_CPSetNetworkType(ConnectionProfileID, CFGCXT.type); |
||
207 | |||
208 | /* Kick off connection now... */ |
||
209 | WF_CMConnect(ConnectionProfileID); |
||
210 | /* Change state and return TRUE to show we are done! */ |
||
211 | CFGCXT.cfg_state = cfg_stopped; |
||
212 | |||
213 | return 1; |
||
214 | } |
||
215 | #endif /* STACK_USE_EZ_CONFIG */ |
||
216 | |||
217 | #if defined ( EZ_CONFIG_SCAN ) |
||
218 | void WFInitScan(void) |
||
219 | { |
||
220 | SCANCXT.scanState = 0; |
||
221 | SCANCXT.numScanResults = 0; |
||
222 | SCANCXT.displayIdx = 0; |
||
223 | |||
224 | return; |
||
225 | } |
||
226 | |||
227 | UINT16 WFStartScan(void) |
||
228 | { |
||
229 | /* If scan already in progress bail out */ |
||
230 | if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) |
||
231 | return WF_ERROR_OPERATION_CANCELLED; |
||
232 | |||
233 | WF_Scan(WF_SCAN_ALL); |
||
234 | |||
235 | SCAN_SET_IN_PROGRESS(SCANCXT.scanState); |
||
236 | /* Should they be invalidated??? */ |
||
237 | //SCAN_CLEAR_VALID(SCANCXT.scanState); |
||
238 | |||
239 | return WF_SUCCESS; |
||
240 | } |
||
241 | |||
242 | UINT16 WFRetrieveScanResult(UINT8 Idx, tWFScanResult *p_ScanResult) |
||
243 | { |
||
244 | if (Idx >= SCANCXT.numScanResults) |
||
245 | return WF_ERROR_INVALID_PARAM; |
||
246 | |||
247 | WF_ScanGetResult(Idx, p_ScanResult); |
||
248 | p_ScanResult->ssid[p_ScanResult->ssidLen] = 0; /* Terminate */ |
||
249 | |||
250 | return WF_SUCCESS; |
||
251 | } |
||
252 | |||
253 | void WFScanEventHandler(UINT16 scanResults) |
||
254 | { |
||
255 | /* Cache number APs found in scan */ |
||
256 | SCANCXT.numScanResults = scanResults; |
||
257 | |||
258 | /* Clear the scan in progress */ |
||
259 | SCAN_CLEAR_IN_PROGRESS(SCANCXT.scanState); |
||
260 | SCAN_SET_VALID(SCANCXT.scanState); |
||
261 | |||
262 | return; |
||
263 | } |
||
264 | #endif /* EZ_CONFIG_SCAN */ |
||
265 | |||
266 | #if defined ( WF_CONSOLE ) && defined ( EZ_CONFIG_SCAN ) |
||
267 | extern void |
||
268 | WFDisplayScanMgr() |
||
269 | { |
||
270 | tWFScanResult bssDesc; |
||
271 | char ssid[32]; |
||
272 | |||
273 | if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) |
||
274 | return; |
||
275 | |||
276 | if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) |
||
277 | return; |
||
278 | |||
279 | if (!IS_SCAN_STATE_VALID(SCANCXT.scanState)) |
||
280 | return; |
||
281 | |||
282 | WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc); |
||
283 | |||
284 | /* Display SSID */ |
||
285 | sprintf(ssid, "%s\r\n", bssDesc.ssid); |
||
286 | putsUART(ssid); |
||
287 | |||
288 | if (++SCANCXT.displayIdx == SCANCXT.numScanResults) { |
||
289 | SCAN_CLEAR_DISPLAY(SCANCXT.scanState); |
||
290 | SCANCXT.displayIdx = 0; |
||
291 | #if defined(WF_CONSOLE) |
||
292 | WFConsoleReleaseConsoleMsg(); |
||
293 | #endif |
||
294 | } |
||
295 | |||
296 | return; |
||
297 | } |
||
298 | #endif /* WF_CONSOLE */ |
||
299 | |||
300 | #endif /* WF_CS_TRIS */ |
Powered by WebSVN v2.8.3