/*----------------------------------------------------------------------------- Routine Name: scan_get_by_bssid Routine Description: Gets scan_result pointer to item by bssid Arguments: mydrv - pointer to private driver data structure bssid - pointer to bssid value Return Value: pointer to scan_result item -----------------------------------------------------------------------------*/ scan_result_t *scan_get_by_bssid( struct wpa_driver_ti_data *mydrv, u8 *bssid ) { SHLIST *head = &(mydrv->scan_merge_list); SHLIST *item; scan_result_t *cur_res; scan_ssid_t *p_ssid; item = shListGetFirstItem(head); if( item == NULL ) return( NULL ); do { cur_res = (scan_result_t *)&(((scan_merge_t *)(item->data))->scanres); p_ssid = scan_get_ssid(cur_res); if( (!os_memcmp(cur_res->bssid, bssid, ETH_ALEN)) && (!IS_HIDDEN_AP(p_ssid)) ) { return( cur_res ); } item = shListGetNextItem(head, item); } while( item != NULL ); return( NULL ); }
unsigned int scan_merge( struct wpa_driver_ti_data *mydrv, scan_result_t *results, int force_flag, unsigned int number_items, unsigned int max_size ) #endif { SHLIST *head = &(mydrv->scan_merge_list); SHLIST *item, *del_item; scan_result_t *res_ptr; scan_merge_t *scan_ptr; unsigned int i; /* Prepare items for removal */ item = shListGetFirstItem(head); while( item != NULL ) { scan_ptr = (scan_merge_t *)(item->data); if( scan_ptr->count != 0 ) scan_ptr->count--; item = shListGetNextItem(head, item); } for(i=0;( i < number_items );i++) { /* Find/Add new items */ #if defined WPA_SUPPLICANT_VER_0_6_X || defined WPA_SUPPLICANT_VER_0_8_X res_ptr = results[i]; #else res_ptr = &(results[i]); #endif item = shListFindItem( head, res_ptr, scan_equal ); if( item ) { #if defined WPA_SUPPLICANT_VER_0_6_X || defined WPA_SUPPLICANT_VER_0_8_X scan_ssid_t *p_ssid; scan_result_t *new_ptr; #endif scan_ptr = (scan_merge_t *)(item->data); copy_scan_res(&(scan_ptr->scanres), res_ptr); scan_ptr->count = SCAN_MERGE_COUNT; #if defined WPA_SUPPLICANT_VER_0_6_X || defined WPA_SUPPLICANT_VER_0_8_X p_ssid = scan_get_ssid(res_ptr); if (p_ssid && IS_HIDDEN_AP(p_ssid)) { new_ptr = scan_dup(res_ptr); if (new_ptr) { results[i] = new_ptr; os_free(res_ptr); } } #endif } else { scan_add(head, res_ptr); } } item = shListGetFirstItem( head ); /* Add/Remove missing items */ while( item != NULL ) { del_item = NULL; scan_ptr = (scan_merge_t *)(item->data); if( scan_ptr->count != SCAN_MERGE_COUNT ) { if( !force_flag && ((scan_ptr->count == 0) || (mydrv->last_scan == SCAN_TYPE_NORMAL_ACTIVE)) ) { del_item = item; } else { if( number_items < max_size ) { #if defined WPA_SUPPLICANT_VER_0_6_X || defined WPA_SUPPLICANT_VER_0_8_X res_ptr = scan_dup(&(scan_ptr->scanres)); if (res_ptr) { results[number_items] = res_ptr; number_items++; } #else os_memcpy(&(results[number_items]), &(scan_ptr->scanres), sizeof(scan_result_t)); number_items++; #endif } } } item = shListGetNextItem(head, item); shListDelItem(head, del_item, scan_free); } return( number_items ); }
static void *stdin_read_thread(void *x) { int fd, fdi; unsigned char buf[1024]; #ifdef SH_HISTORY unsigned char realbuf[1024], *buf_ptr; SHLIST history; SHLIST *item = &history; int cmdlen = 0, ins_flag = 0; #endif int r, n; int state = 0; int *fds = (int*) x; fd = fds[0]; fdi = fds[1]; free(fds); #ifdef SH_HISTORY shListInitList( &history ); #endif for(;;) { /* fdi is really the client's stdin, so use read, not adb_read here */ r = unix_read(fdi, buf, 1024); if(r == 0) break; if(r < 0) { if(errno == EINTR) continue; break; } #ifdef SH_HISTORY if( (r == 3) && /* Arrow processing */ (memcmp( (void *)buf, SH_ARROW_ANY, 2 ) == 0) ) { switch( buf[2] ) { case SH_ARROW_UP: item = shListGetNextItem( &history, item ); break; case SH_ARROW_DOWN: item = shListGetPrevItem( &history, item ); break; default: item = NULL; break; } memset( buf, SH_DEL_CHAR, cmdlen ); if( item != NULL ) { n = snprintf( (char *)(&buf[cmdlen]), sizeof buf - cmdlen, "%s", (char *)(item->data) ); memcpy( realbuf, item->data, n ); } else { /* Clean buffer */ item = &history; n = 0; } r = n + cmdlen; cmdlen = n; ins_flag = 0; if( r == 0 ) continue; } else { #endif for(n = 0; n < r; n++){ switch(buf[n]) { case '\n': #ifdef SH_HISTORY if( ins_flag && (SH_BLANK_CHAR <= realbuf[0]) ) { buf_ptr = malloc(cmdlen + 1); if( buf_ptr != NULL ) { memcpy( buf_ptr, realbuf, cmdlen ); buf_ptr[cmdlen] = '\0'; if( (item = shListFindItem( &history, (void *)buf_ptr, shItemCmp )) == NULL ) { shListInsFirstItem( &history, (void *)buf_ptr ); item = &history; } } } cmdlen = 0; ins_flag = 0; #endif state = 1; break; case '\r': state = 1; break; case '~': if(state == 1) state++; break; case '.': if(state == 2) { fprintf(stderr,"\n* disconnect *\n"); #ifdef HAVE_TERMIO_H stdin_raw_restore(fdi); #endif exit(0); } default: #ifdef SH_HISTORY if( buf[n] == SH_DEL_CHAR ) { if( cmdlen > 0 ) cmdlen--; } else { realbuf[cmdlen] = buf[n]; cmdlen++; } ins_flag = 1; #endif state = 0; } } #ifdef SH_HISTORY } #endif r = adb_write(fd, buf, r); if(r <= 0) { break; } } #ifdef SH_HISTORY shListDelAllItems( &history, (shListFree)free ); #endif return 0; }