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 301 of file wl_cm.c.
References cm_candidate::bssid, cm::candidate, and cm_candidate::ssid.
Referenced by cmd_connect(), gui_connect_cb(), set_wep_key_cb(), and set_wpa_key_cb().
00302 { 00303 if (cm == NULL) 00304 return WL_FAILURE; 00305 00306 if (ssid) 00307 memcpy(&cm->candidate.ssid, ssid, sizeof(cm->candidate.ssid)); 00308 else 00309 cm->candidate.ssid.len = 0; 00310 00311 if (bssid) 00312 memcpy(&cm->candidate.bssid, bssid, 00313 sizeof(cm->candidate.bssid)); 00314 else 00315 memset(&cm->candidate.bssid, 0xff, sizeof(cm->candidate.bssid)); 00316 (void) wl_scan(); 00317 return WL_SUCCESS; 00318 }
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 256 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().
00260 { 00261 if (cm != NULL) 00262 return WL_FAILURE; 00263 00264 cm = calloc(1, sizeof(struct cm)); 00265 if (cm == NULL) { 00266 CM_DPRINTF("CM: out of memory\n"); 00267 return WL_FAILURE; 00268 } 00269 00270 if (wl_register_event_cb(wl_event_cb, cm) != WL_SUCCESS) { 00271 CM_DPRINTF("CM: could not register event cb\n"); 00272 return WL_FAILURE; 00273 } 00274 00275 cm->scan_cb = scan_cb; 00276 cm->conn_cb = conn_cb; 00277 cm->disconn_cb = disconn_cb; 00278 cm->ctx = ctx; 00279 if (wl_scan() != WL_SUCCESS) 00280 CM_DPRINTF("CM: could not scan\n"); 00281 00282 CM_DPRINTF("CM: initialized\n"); 00283 return WL_SUCCESS; 00284 }
static void wl_conn_failure_cb | ( | void * | ctx | ) | [static] |
Definition at line 186 of file wl_cm.c.
References CM_DPRINTF.
Referenced by wl_event_cb().
00187 { 00188 CM_DPRINTF("CM: connect failed, scanning\n"); 00189 00190 if (wl_scan() != WL_SUCCESS) 00191 /* should never happen */ 00192 CM_DPRINTF("CM: could not start scan after connect fail!\n"); 00193 }
static void wl_conn_lost_cb | ( | void * | ctx | ) | [static] |
Definition at line 200 of file wl_cm.c.
References CM_DPRINTF, cm::ctx, and cm::disconn_cb.
Referenced by wl_event_cb().
00201 { 00202 struct cm *cm = ctx; 00203 CM_DPRINTF("CM: connection lost, scanning\n"); 00204 00205 if (cm->disconn_cb) 00206 cm->disconn_cb(cm->ctx); 00207 00208 if (wl_scan() != WL_SUCCESS) 00209 /* should never happen */ 00210 CM_DPRINTF("CM: could not start scan after connect lost!\n"); 00211 }
static void wl_event_cb | ( | struct wl_event_t | event, | |
void * | ctx | |||
) | [static] |
Definition at line 218 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().
00219 { 00220 struct cm *cm = ctx; 00221 00222 switch (event.id) { 00223 case WL_EVENT_MEDIA_CONNECTED: 00224 wl_media_connected_cb(cm); 00225 break; 00226 00227 case WL_EVENT_CONN_FAILURE: 00228 wl_conn_failure_cb(cm); 00229 break; 00230 00231 case WL_EVENT_MEDIA_DISCONNECTED: 00232 CM_DPRINTF("CM: disconnected\n"); 00233 wl_conn_lost_cb(cm); 00234 break; 00235 00236 case WL_EVENT_CONN_LOST: 00237 wl_conn_lost_cb(cm); 00238 break; 00239 00240 case WL_EVENT_SCAN_COMPLETE: 00241 wl_scan_complete_cb(cm); 00242 break; 00243 00244 default: 00245 CM_DPRINTF("CM: unhandled event\n"); 00246 }; 00247 }
static void wl_media_connected_cb | ( | void * | ctx | ) | [static] |
Definition at line 172 of file wl_cm.c.
References CM_DPRINTF, cm::conn_cb, cm::ctx, and ssid2str().
Referenced by wl_event_cb().
00173 { 00174 struct cm *cm = ctx; 00175 struct wl_network_t *net = wl_get_current_network(); 00176 CM_DPRINTF("CM: connected to %s\n", ssid2str(&net->ssid)); 00177 if (cm->conn_cb) 00178 cm->conn_cb(net, cm->ctx); 00179 }
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] |