Data Structures | |
struct | cm |
struct | cm_candidate |
Functions | |
static struct wl_network_t * | find_best_candidate (struct cm *cm) |
static void | select_net (struct cm *cm) |
wl_err_t | wl_cm_set_network (struct wl_ssid_t *ssid, struct wl_mac_addr_t *bssid) |
Set the desired network which the connection manager should try to connect to. | |
wl_err_t | wl_cm_start (cm_scan_cb_t scan_cb, cm_conn_cb_t conn_cb, cm_disconn_cb_t disconn_cb, void *ctx) |
static void | wl_conn_failure_cb (void *ctx) |
static void | wl_conn_lost_cb (void *ctx) |
static void | wl_event_cb (struct wl_event_t event, void *ctx) |
static void | wl_media_connected_cb (void *ctx) |
static void | wl_scan_complete_cb (void *ctx) |
Variables | |
struct wl_mac_addr_t | cm_candidate::bssid |
struct cm_candidate | cm::candidate |
static struct cm * | cm = NULL |
cm_conn_cb_t * | cm::conn_cb |
void * | cm::ctx |
cm_disconn_cb_t * | cm::disconn_cb |
static struct wl_network_t* find_best_candidate | ( | struct cm * | cm | ) | [static, read] |
Definition at line 70 of file wl_cm.c.
References cm_candidate::bssid, cm::candidate, cnt, equal_bssid(), equal_ssid(), and cm_candidate::ssid.
Referenced by select_net().
00071 { 00072 struct wl_network_t* wl_network; 00073 uint8_t cnt, i; 00074 00075 wl_get_network_list(&wl_network, &cnt); 00076 if (cnt == 0) 00077 return NULL; 00078 00079 for (i = 0; i < cnt; i++) { 00080 /* match on ssid */ 00081 if (cm->candidate.ssid.len) 00082 if (!equal_ssid(&cm->candidate.ssid, 00083 &wl_network[i].ssid)) 00084 continue; 00085 00086 /* match bssid */ 00087 if (strncmp((char*) cm->candidate.bssid.octet, 00088 "\xff\xff\xff\xff\xff\xff", 6)) 00089 if (!equal_bssid(&cm->candidate.bssid, 00090 &wl_network[i].bssid)) 00091 continue; 00092 00093 /* anything will do */ 00094 return &wl_network[i]; 00095 } 00096 00097 return NULL; 00098 }
static void select_net | ( | struct cm * | cm | ) | [static] |
Definition at line 105 of file wl_cm.c.
References cm::candidate, CM_DPRINTF, find_best_candidate(), and cm_candidate::ssid.
Referenced by wl_scan_complete_cb().
00106 { 00107 struct wl_network_t *candidate_net; 00108 struct wl_network_t *current_net; 00109 int ret; 00110 00111 current_net = wl_get_current_network(); 00112 candidate_net = find_best_candidate(cm); 00113 00114 /* disconnected, and no candidate found? */ 00115 if (cm->candidate.ssid.len != 0 && current_net == NULL && candidate_net == NULL) { 00116 ; /* to scan */ 00117 00118 /* already connected to the candidate? */ 00119 } else if (current_net == candidate_net) { 00120 return; 00121 00122 /* disconnected, and a candidate is found */ 00123 } else if (current_net == NULL && candidate_net) { 00124 ret = wl_connect(candidate_net->ssid.ssid, 00125 candidate_net->ssid.len); 00126 switch (ret) { 00127 case WL_SUCCESS : 00128 return; 00129 case WL_BUSY: 00130 wl_disconnect(); 00131 return; 00132 default : 00133 break; 00134 } 00135 00136 CM_DPRINTF("CM: failed to connect\n"); 00137 00138 /* connected, but another (or no valid) candidate was found */ 00139 } else if (current_net) { 00140 if (wl_disconnect() == WL_SUCCESS) 00141 return; 00142 00143 CM_DPRINTF("CM: failed to disconnect\n"); 00144 } 00145 00146 /* some operation failed or no candidate found */ 00147 if (wl_scan() != WL_SUCCESS) 00148 CM_DPRINTF("CM: failed to scan\n"); 00149 }
wl_err_t wl_cm_set_network | ( | struct wl_ssid_t * | ssid, | |
struct wl_mac_addr_t * | bssid | |||
) |
Set the desired network which the connection manager should try to connect to.
The ssid and bssid of the desired network should be specified. The ssid and bssid will be matched against the networks found during scan. If any parameter is null, it will always match. If both parameters are null, the first found network will be chosen.
ssid | The ssid of the desired network. If null, any ssid will match. | |
bssid | The bssid of the desired network. If null, any bssid will match. |
Definition at line 305 of file wl_cm.c.
References cm_candidate::bssid, cm::candidate, and cm_candidate::ssid.
Referenced by cmd_connect(), and gui_connect_cb().
00306 { 00307 if (cm == NULL) 00308 return WL_FAILURE; 00309 00310 if (ssid) 00311 memcpy(&cm->candidate.ssid, ssid, sizeof(cm->candidate.ssid)); 00312 else 00313 cm->candidate.ssid.len = 0; 00314 00315 if (bssid) 00316 memcpy(&cm->candidate.bssid, bssid, 00317 sizeof(cm->candidate.bssid)); 00318 else 00319 memset(&cm->candidate.bssid, 0xff, sizeof(cm->candidate.bssid)); 00320 (void) wl_scan(); 00321 return WL_SUCCESS; 00322 }
wl_err_t wl_cm_start | ( | cm_scan_cb_t | scan_cb, | |
cm_conn_cb_t | conn_cb, | |||
cm_disconn_cb_t | disconn_cb, | |||
void * | ctx | |||
) |
Definition at line 260 of file wl_cm.c.
References CM_DPRINTF, cm::conn_cb, cm::ctx, cm::disconn_cb, cm::scan_cb, and wl_event_cb().
Referenced by wl_init_complete_cb().
00264 { 00265 if (cm != NULL) 00266 return WL_FAILURE; 00267 00268 cm = calloc(1, sizeof(struct cm)); 00269 if (cm == NULL) { 00270 CM_DPRINTF("CM: out of memory\n"); 00271 return WL_FAILURE; 00272 } 00273 00274 if (wl_register_event_cb(wl_event_cb, cm) != WL_SUCCESS) { 00275 CM_DPRINTF("CM: could not register event cb\n"); 00276 return WL_FAILURE; 00277 } 00278 00279 cm->scan_cb = scan_cb; 00280 cm->conn_cb = conn_cb; 00281 cm->disconn_cb = disconn_cb; 00282 cm->ctx = ctx; 00283 if (wl_scan() != WL_SUCCESS) 00284 CM_DPRINTF("CM: could not scan\n"); 00285 00286 CM_DPRINTF("CM: initialized\n"); 00287 return WL_SUCCESS; 00288 }
static void wl_conn_failure_cb | ( | void * | ctx | ) | [static] |
Definition at line 190 of file wl_cm.c.
References CM_DPRINTF.
Referenced by wl_event_cb().
00191 { 00192 CM_DPRINTF("CM: connect failed, scanning\n"); 00193 00194 if (wl_scan() != WL_SUCCESS) 00195 /* should never happen */ 00196 CM_DPRINTF("CM: could not start scan after connect fail!\n"); 00197 }
static void wl_conn_lost_cb | ( | void * | ctx | ) | [static] |
Definition at line 204 of file wl_cm.c.
References CM_DPRINTF, cm::ctx, and cm::disconn_cb.
Referenced by wl_event_cb().
00205 { 00206 struct cm *cm = ctx; 00207 CM_DPRINTF("CM: connection lost, scanning\n"); 00208 00209 if (cm->disconn_cb) 00210 cm->disconn_cb(cm->ctx); 00211 00212 if (wl_scan() != WL_SUCCESS) 00213 /* should never happen */ 00214 CM_DPRINTF("CM: could not start scan after connect lost!\n"); 00215 }
static void wl_event_cb | ( | struct wl_event_t | event, | |
void * | ctx | |||
) | [static] |
Definition at line 222 of file wl_cm.c.
References CM_DPRINTF, wl_conn_failure_cb(), wl_conn_lost_cb(), wl_media_connected_cb(), and wl_scan_complete_cb().
Referenced by wl_cm_start().
00223 { 00224 struct cm *cm = ctx; 00225 00226 switch (event.id) { 00227 case WL_EVENT_MEDIA_CONNECTED: 00228 wl_media_connected_cb(cm); 00229 break; 00230 00231 case WL_EVENT_CONN_FAILURE: 00232 wl_conn_failure_cb(cm); 00233 break; 00234 00235 case WL_EVENT_MEDIA_DISCONNECTED: 00236 CM_DPRINTF("CM: disconnected\n"); 00237 wl_conn_lost_cb(cm); 00238 break; 00239 00240 case WL_EVENT_CONN_LOST: 00241 wl_conn_lost_cb(cm); 00242 break; 00243 00244 case WL_EVENT_SCAN_COMPLETE: 00245 wl_scan_complete_cb(cm); 00246 break; 00247 00248 default: 00249 CM_DPRINTF("CM: unhandled event\n"); 00250 }; 00251 }
static void wl_media_connected_cb | ( | void * | ctx | ) | [static] |
Definition at line 172 of file wl_cm.c.
References CM_DPRINTF, cm::conn_cb, and cm::ctx.
Referenced by wl_event_cb().
00173 { 00174 struct cm *cm = ctx; 00175 struct wl_network_t *net = wl_get_current_network(); 00176 char ssid[WL_SSID_MAX_LENGTH + 1]; 00177 00178 memset(ssid, 0, sizeof(ssid)); 00179 strncpy(ssid, net->ssid.ssid, net->ssid.len); 00180 CM_DPRINTF("CM: connected to %s\n", ssid); 00181 if (cm->conn_cb) 00182 cm->conn_cb(net, cm->ctx); 00183 }
static void wl_scan_complete_cb | ( | void * | ctx | ) | [static] |
Definition at line 156 of file wl_cm.c.
References CM_DPRINTF, cm::ctx, cm::scan_cb, and select_net().
Referenced by wl_event_cb().
00157 { 00158 struct cm *cm = ctx; 00159 00160 CM_DPRINTF("CM: scan completed\n"); 00161 00162 if (cm->scan_cb) 00163 cm->scan_cb(cm->ctx); 00164 00165 select_net(cm); 00166 }
struct wl_mac_addr_t cm_candidate::bssid [read, inherited] |
Definition at line 53 of file wl_cm.c.
Referenced by find_best_candidate(), and wl_cm_set_network().
struct cm_candidate cm::candidate [read, inherited] |
Definition at line 62 of file wl_cm.c.
Referenced by find_best_candidate(), select_net(), and wl_cm_set_network().
cm_conn_cb_t* cm::conn_cb [inherited] |
void* cm::ctx [inherited] |
Definition at line 60 of file wl_cm.c.
Referenced by wl_cm_start(), wl_conn_lost_cb(), wl_media_connected_cb(), and wl_scan_complete_cb().
cm_disconn_cb_t* cm::disconn_cb [inherited] |