static void wl_conn_failure_cb(void* ctx) { CM_DPRINTF("CM: connect failed, scanning\n"); if (wl_scan() != WL_SUCCESS) /* should never happen */ CM_DPRINTF("CM: could not start scan after connect fail!\n"); }
cmd_state_t cmd_scan(int argc, char* argv[], void* ctx) { /* Note that the scan results presented will * be from the last scan, not this one. */ wl_scan(); print_network_list(); return CMD_DONE; }
static void wl_conn_lost_cb(void* ctx) { struct cm *cm = ctx; CM_DPRINTF("CM: connection lost, scanning\n"); if (cm->disconn_cb) cm->disconn_cb(cm->ctx); if (wl_scan() != WL_SUCCESS) /* should never happen */ CM_DPRINTF("CM: could not start scan after connect lost!\n"); }
static void wl_conn_failure_cb(void* ctx) { struct cm *cm = ctx; CM_DPRINTF("CM: connect failed, scanning\n"); ERROR_LED_ON(); LINK_LED_OFF(); if ( 0 == cm->enabled ) { return; } if (wl_scan() != WL_SUCCESS) /* should never happen */ CM_DPRINTF("CM: could not start scan after connect fail!\n"); }
void sta_start_scanning() { if (sta_state==STA_STATE_BEING_AP) { stop_dhcpd(); if (nvram_match("wlp_clientmode_x", "2")) nvram_set("wl0_mode", "wet"); else nvram_set("wl0_mode", "sta"); eval("wlconfig", "eth2"); } wl_scan(); time(&sta_timer); sta_state = STA_STATE_SCANNING; sta_status_report(sta_state, 0); }
void wl_init_complete_cb(void* ctx) { struct ctx_server *hs = ctx; struct ip_addr ipaddr, netmask, gw; wl_err_t wl_status; if (hs->net_cfg.dhcp_enabled == INIT_IP_CONFIG) { IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); /* default is dhcp enabled */ hs->net_cfg.dhcp_enabled = DYNAMIC_IP_CONFIG; } start_ip_stack(&hs->net_cfg, ipaddr, netmask, gw); netif_set_status_callback(hs->net_cfg.netif, ip_status_cb); INFO_INIT("Starting CM...\n"); /* start connection manager */ wl_status = wl_cm_init(wl_cm_scan_cb, wl_cm_conn_cb, wl_cm_disconn_cb, hs); ASSERT(wl_status == WL_SUCCESS, "failed to init wl conn mgr"); wl_cm_start(); wl_scan(); if (initSpi(hs)){ WARN("Spi not initialized\n"); }else { initSpiComplete = true; AVAIL_FOR_SPI(); } hs->wl_init_complete = 1; }
/** * 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. * * @param ssid The ssid of the desired network. If null, any ssid will match. * @param bssid The bssid of the desired network. If null, any bssid will match. * */ wl_err_t wl_cm_set_network(struct wl_ssid_t *ssid, struct wl_mac_addr_t *bssid) { if (cm == NULL) return WL_FAILURE; if (ssid) memcpy(&cm->candidate.ssid, ssid, sizeof(cm->candidate.ssid)); else cm->candidate.ssid.len = 0; if (bssid) memcpy(&cm->candidate.bssid, bssid, sizeof(cm->candidate.bssid)); else memset(&cm->candidate.bssid, 0xff, sizeof(cm->candidate.bssid)); if (cm->candidate.ssid.len) wl_scan(); return WL_SUCCESS; }
static void psta_keepalive() { char tmp[NVRAM_BUFSIZE], prefix[] = "wlXXXXXXXXXX_"; char *name = NULL; struct maclist *mac_list = NULL; int mac_list_size, i, unit; int psta = 0; struct ether_addr bssid; unsigned char bssid_null[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; char macaddr[18]; unit = nvram_get_int("wlc_band"); snprintf(prefix, sizeof(prefix), "wl%d_", unit); if (!nvram_match(strcat_r(prefix, "mode", tmp), "psta")) goto PSTA_ERR; name = nvram_safe_get(strcat_r(prefix, "ifname", tmp)); if (wl_ioctl(name, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN) != 0) goto PSTA_ERR; else if (!memcmp(&bssid, bssid_null, 6)) goto PSTA_ERR; /* buffers and length */ mac_list_size = sizeof(mac_list->count) + MAX_STA_COUNT * sizeof(struct ether_addr); mac_list = malloc(mac_list_size); if (!mac_list) goto PSTA_ERR; /* query wl for authenticated sta list */ strcpy((char*)mac_list, "authe_sta_list"); if (wl_ioctl(name, WLC_GET_VAR, mac_list, mac_list_size)) { free(mac_list); goto PSTA_ERR; } /* query sta_info for each STA and output one table row each */ if (mac_list->count) { if (nvram_match(strcat_r(prefix, "akm", tmp), "")) psta = 1; else for (i = 0; i < mac_list->count; i++) { if (wl_autho(name, &mac_list->ea[i])) { psta = 1; break; } } } PSTA_ERR: if (psta) { count_bss_down = 0; ether_etoa((const unsigned char *) &bssid, macaddr); if (psta_debug) dbg("psta send keepalive nulldata to %s\n", macaddr); eval("wl", "-i", name, "send_nulldata", macaddr); #ifdef PSTA_DEBUG count = (count + 1) % 10; if (!count) check_wl_rate(name); #endif } else { if (psta_debug) dbg("psta disconnected\n"); if (++count_bss_down > 9) { count_bss_down = 0; if (wl_scan(unit)) { eval("wlconf", name, "down"); eval("wlconf", name, "up"); eval("wlconf", name, "start"); } } else { eval("wl", "-i", name, "bss", "down"); eval("wl", "-i", name, "down"); eval("wl", "-i", name, "up"); eval("wl", "-i", name, "bss", "up"); } } if (mac_list) free(mac_list); }
static void select_net(struct cm* cm) { struct wl_network_t *candidate_net; struct wl_network_t *current_net; struct wl_ssid_t *ssid_p; int ret; /* Nothing to do */ if (0 == cm->candidate.ssid.len) { return; } current_net = wl_get_current_network(); candidate_net = find_best_candidate(cm); /* Connected to the candidate? ... */ if ( current_net == candidate_net ) { if ( current_net ) { /* ...yes, dont change. */ return; } } /* Roaming checks */ if (current_net && candidate_net) { /* Are we changing BSSs? */ if ( equal_ssid(&candidate_net->ssid, ¤t_net->ssid)) { /* ...no. Does the currently connected * net have a decent RSSI?...*/ if ( current_net->rssi > ROAMING_RSSI_THRESHOLD ) { /* ...yes, stay with it. */ return; } /* ...no. Does the candidate have * sufficiently better RSSI to * motivate a switch to it? */ if ( candidate_net->rssi < current_net->rssi + ROAMING_RSSI_DIFF) { return; } /* ...yes, try to roam to candidate_net */ CM_DPRINTF("CM: Roaming from rssi %d to %d\n", current_net->rssi, candidate_net->rssi); } } /* a candidate is found */ if (candidate_net) { /* We connect to a specific bssid here because * find_best_candidate() might have picked a * particulare AP among many with the same SSID. * wl_connect() would pick one of them at random. */ ret = wl_connect_bssid(candidate_net->bssid); } /* no candidate found */ else { CM_DPRINTF("CM: No candidate found for ssid \"%s\"\n", ssid2str(&cm->candidate.ssid)); /* Might be a hidden SSID so we try to connect to it. * wl_connect() will trigger a directed scan * for the SSID in this case. */ ssid_p = &cm->candidate.ssid; ret = wl_connect(ssid_p->ssid, ssid_p->len); } switch (ret) { case WL_SUCCESS : return; case WL_BUSY: wl_disconnect(); return; case WL_RETRY: break; default : CM_DPRINTF("CM: failed to connect\n"); break; } /* some operation failed or no candidate found */ if (wl_scan() != WL_SUCCESS) CM_DPRINTF("CM: failed to scan\n"); }