?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 MRF24WB0M Driver Connection Manager
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: WFConnectionManager.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 /*
52 *********************************************************************************************************
53 * INCLUDES
54 *********************************************************************************************************
55 */
56  
57 #include "TCPIP Stack/WFMac.h"
58  
59 #if defined(WF_CS_TRIS)
60  
61  
62 /* used for assertions */
63 #ifdef WF_DEBUG
64 #define WF_MODULE_NUMBER WF_MODULE_WF_CONNECTION_MANAGER
65 #endif
66  
67  
68 /*
69 *********************************************************************************************************
70 * LOCAL GLOBAL VARIABLES
71 *********************************************************************************************************
72 */
73  
74 static BOOL g_LogicalConnection = FALSE;
75  
76  
77 /*******************************************************************************
78 Function:
79 void WF_CMConnect(UINT8 CpId)
80  
81 Summary:
82 Commands the MRF24WB0M to start a connection.
83  
84 Description:
85 Directs the Connection Manager to scan for and connect to a WiFi network.
86 This function does not wait until the connection attempt is successful, but
87 returns immediately. See WF_ProcessEvent for events that can occur as a
88 result of a connection attempt being successful or not.
89  
90 Note that if the Connection Profile being used has WPA or WPA2 security
91 enabled and is using a passphrase, the connection manager will first
92 calculate the PSK key, and then start the connection process. The key
93 calculation can take up to 30 seconds.
94  
95 Precondition:
96 MACInit must be called first.
97  
98 Parameters:
99 CpId -- If this value is equal to an existing Connection Profile’s ID than
100 only that Connection Profile will be used to attempt a connection to
101 a WiFi network.
102 If this value is set to WF_CM_CONNECT_USING_LIST then the
103 connectionProfileList will be used to connect, starting with the
104 first Connection Profile in the list.
105  
106 Returns:
107 None.
108  
109 Remarks:
110 None.
111 *****************************************************************************/
112 void WF_CMConnect(UINT8 CpId)
113 {
114 UINT8 hdrBuf[4];
115  
116 /* Write out header portion of msg (which is whole msg, there is no data) */
117 hdrBuf[0] = WF_MGMT_REQUEST_TYPE; /* indicate this is a mgmt msg */
118 hdrBuf[1] = WF_CM_CONNECT_SUBYTPE; /* mgmt request subtype */
119 hdrBuf[2] = CpId;
120 hdrBuf[3] = 0;
121  
122 SendMgmtMsg(hdrBuf,
123 sizeof(hdrBuf),
124 NULL,
125 0);
126  
127 /* wait for mgmt response, free after it comes in, don't need data bytes */
128 WaitForMgmtResponse(WF_CM_CONNECT_SUBYTPE, FREE_MGMT_BUFFER);
129 }
130  
131 /*******************************************************************************
132 Function:
133 void WF_CMDisconnect(void)
134  
135 Summary:
136 Commands the MRF24WB0M to close any open connections and/or to cease
137 attempting to connect.
138  
139 Description:
140 Directs the Connection Manager to close any open connection or connection
141 attempt in progress. No further attempts to connect are taken until
142 WF_CMConnect() is called. Generates the event
143 WF_EVENT_CONNECTION_PERMANENTLY_LOST when the connection is successfully
144 terminated.
145  
146 Precondition:
147 MACInit must be called.
148  
149 Parameters:
150 None.
151  
152 Returns:
153 None.
154  
155 Remarks:
156 None.
157 *****************************************************************************/
158 void WF_CMDisconnect(void)
159 {
160 UINT8 hdrBuf[2];
161  
162 hdrBuf[0] = WF_MGMT_REQUEST_TYPE;
163 hdrBuf[1] = WF_CM_DISCONNECT_SUBYTPE;
164  
165 SendMgmtMsg(hdrBuf,
166 sizeof(hdrBuf),
167 NULL,
168 0);
169  
170 /* wait for mgmt response, free after it comes in, don't need data bytes */
171 WaitForMgmtResponse(WF_CM_DISCONNECT_SUBYTPE, FREE_MGMT_BUFFER);
172  
173 /* set state to no connection */
174 SetLogicalConnectionState(FALSE);
175 }
176  
177 /*******************************************************************************
178 Function:
179 void WF_CMGetConnectionState(UINT8 *p_state, UINT8 *p_currentCpId)
180  
181 Summary:
182 Returns the current connection state.
183  
184 Description:
185  
186 Precondition:
187 MACInit must be called first.
188  
189 Parameters:
190 p_state -- Pointer to location where connection state will be written
191 p_currentCpId -- Pointer to location of current connection profile ID that
192 is being queried.
193  
194 Returns:
195 None.
196  
197 Remarks:
198 None.
199 *****************************************************************************/
200 void WF_CMGetConnectionState(UINT8 *p_state, UINT8 *p_currentCpId)
201 {
202 UINT8 hdrBuf[2];
203 UINT8 msgData[2];
204  
205 hdrBuf[0] = WF_MGMT_REQUEST_TYPE;
206 hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE;
207  
208 SendMgmtMsg(hdrBuf,
209 sizeof(hdrBuf),
210 NULL,
211 0);
212  
213 /* wait for mgmt response, read data, free after read */
214 WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE,
215 sizeof(msgData), /* num data bytes to read */
216 MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */
217 msgData); /* only used if num data bytes > 0 */
218  
219 *p_state = msgData[0]; /* connection state */
220 *p_currentCpId = msgData[1]; /* current CpId */
221  
222 if ((*p_state == WF_CSTATE_NOT_CONNECTED) || (*p_state == WF_CSTATE_CONNECTION_PERMANENTLY_LOST))
223 {
224 SetLogicalConnectionState(FALSE);
225 }
226 else
227 {
228 SetLogicalConnectionState(TRUE);
229 }
230 }
231  
232 /*******************************************************************************
233 Function:
234 BOOL WFisConnected()
235  
236 Summary:
237 Query the connection status of the MRF24WB0M.
238  
239 Description:
240 Determine the fine granularity status of the connection state of the
241 MRF24WB0M.
242  
243 Precondition:
244 MACInit must be called first.
245  
246 Parameters:
247 None.
248  
249 Returns:
250 TRUE if the MRF24WB0M is either connected or attempting to connect.
251 FALSE for all other conditions.
252  
253 Remarks:
254 None.
255 *****************************************************************************/
256 BOOL WFisConnected()
257 {
258 return g_LogicalConnection;
259 }
260  
261 /*******************************************************************************
262 Function:
263 void SetLogicalConnectionState(BOOL state)
264  
265 Summary:
266 Sets the logical connection state.
267  
268 Description:
269 Logically, if the MRF24WB0M is either connected or trying to connect, then
270 it is "connected". For all other scenarios, the MRF24WB0M is "not
271 connected".
272  
273 Precondition:
274 MACInit must be called first.
275  
276 Parameters:
277 state -- Current logical connection state of the MRF24WB0M.
278  
279 Returns:
280 None.
281  
282 Remarks:
283 None.
284 *****************************************************************************/
285 void SetLogicalConnectionState(BOOL state)
286 {
287 g_LogicalConnection = state;
288 }
289  
290 #endif /* WF_CS_TRIS */
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3