void display_node(struct node_info* node) { int x = 0; int y = 0; int i; char chan[3]; char* ssid = 0; int sig, max, left, noise; char* wep = 0; y = node->pos; if (y == -1) // offscreen return; assert(y < LINES); // MAC mvaddstr(y, x, mac2str(node->mac)); x += 6*3; // WEP wep = wep2str(node->wep); assert(wep); mvaddstr(y, x, wep); x += strlen(wep); x++; // CHAN sprintf(chan, "%.2d", node->chan); mvaddstr(y, x, chan); x += 3; // ssid ssid = ssid2str(node); assert(ssid); mvaddstr(y, x, ssid); x += strlen(ssid); x++; left = COLS - x - 1; sig = (int) ( ((double)node->signal)*left/100.0 ); noise=(int) ( ((double)node->noise)*left/100.0 ); max = (int) ( ((double)node->max)*left/100.0 ); // SIGNAL BAR for (i = 0; i < noise; i++) mvaddch(y, x++, 'N'); for (; i < sig; i++) mvaddch(y,x++, 'X'); for (; i < max; i++) mvaddch(y,x++, ' '); mvaddch(y,x++, '|'); for (; x < COLS-1; x++) mvaddch(y, x, ' '); assert (x <= COLS); }
void save_state() { FILE* f; struct node_info* node = nodes; f = fopen("stumbler.log", "w"); if (!f) { perror("fopen()"); exit(1); } while (node) { struct tm* t; char tim[16]; t = localtime( (time_t*) &node->seen.tv_sec); if (!t) { perror("localtime()"); exit(1); } tim[0] = 0; strftime(tim, sizeof(tim), "%H:%M:%S", t); fprintf(f, "%s %s %s %2d %s 0x%.2x\n", tim, mac2str(node->mac), wep2str(node->wep), node->chan, ssid2str(node), node->max); node = node->next; } fclose(f); }
static void wl_media_connected_cb(void* ctx) { struct cm *cm = ctx; struct wl_network_t *net = wl_get_current_network(); CM_DPRINTF("CM: connected to %s\n", ssid2str(&net->ssid)); if (cm->conn_cb) cm->conn_cb(net, cm->ctx); }
void print_network(struct wl_network_t* wl_network) { printk("%s ", mac2str(wl_network->bssid.octet)); printk("\"%s\"", ssid2str(&wl_network->ssid)); printk(" RSSI %d dBm ", wl_network->rssi); switch (wl_network->enc_type) { case ENC_TYPE_WEP : printk(" (WEP encryption)"); break; case ENC_TYPE_TKIP : printk(" (TKIP encryption)"); break; case ENC_TYPE_CCMP : printk(" (CCMP encryption)"); break; case ENC_TYPE_NONE : break; } printk("\n"); }
static void wl_cm_conn_cb(struct wl_network_t* net, void* ctx) { struct ctx_server* hs = ctx; LINK_LED_ON(); INFO_INIT("Connection cb...\n"); printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid)); if ( hs->net_cfg.dhcp_enabled == DYNAMIC_IP_CONFIG ) { INFO_INIT("Start DHCP...\n"); printk("requesting dhcp ... "); int8_t result = dhcp_start(hs->net_cfg.netif); printk((result==ERR_OK)?"OK\n":"FAILED\n"); hs->net_cfg.dhcp_running = 1; } else { netif_set_up(hs->net_cfg.netif); } INFO_INIT("Start DNS...\n"); dns_init(); }
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"); }