struct dbg_request dbg_get_request(struct dbg_context* dbg) { /* Can't ask for the next request until you've satisfied the * current one, for requests that need an immediate * response. */ assert(!request_needs_immediate_response(&dbg->req)); if (sniff_packet(dbg) && dbg_is_resume_request(&dbg->req)) { /* There's no new request data available and gdb has * already asked us to resume. OK, do that (or keep * doing that) now. */ return dbg->req; } while (1) { /* There's either new request data, or we have nothing * to do. Either way, block until we read a complete * packet from gdb. */ read_packet(dbg); if (process_packet(dbg)) { /* We couldn't process the packet internally, * so the target has to do something. */ return dbg->req; } /* The packet we got was "internal", gdb details. * Nothing for the target to do yet. Keep waiting. */ } }
/** * sniffer_engine() <thread> * ---------------------- * the main engine that loops forever(until stopped) reading packets, * organizing, adding, updating to the bss_list data structure. **/ void * sniffer_engine(void *var) { struct SETTINGS *mySettings; struct timeval tv_pot_reset; struct timeval tv_old; struct timeval tv_new; float t_diff; pthread_mutex_lock(&engine_lock); mySettings = (struct SETTINGS*)var; gettimeofday(&tv_pot_reset, NULL); tv_old = tv_pot_reset; engine_status = ENABLED; channel_change = 0; pthread_cond_broadcast(&engine_ready); pthread_mutex_unlock(&engine_lock); while (!stop_scanning){ gettimeofday(&tv_new, NULL); t_diff = get_time_diff(&tv_new, &tv_old); /** do deep scan & analysis **/ if (mySettings->scan_mode == DETAILED_SCAN){ if (t_diff > 1){ pthread_mutex_lock(&engine_lock); update_all_bandwidth(); tv_old = tv_new; pthread_mutex_unlock(&engine_lock); } if (mySettings->runtime_mode == INTERACTIVE){ /** reset the potential structures every 30 secs. **/ t_diff = get_time_diff(&tv_new, &tv_pot_reset); if (t_diff > 30){ /** get lock before resetting structures **/ pthread_mutex_lock(&engine_lock); track_bad_data(); clean_up_bss_nodes(); clear_potential_structs(); pthread_mutex_unlock(&engine_lock); tv_pot_reset = tv_new; } } } if (mySettings->scan_mode == CHANNEL_SCAN){ /** update existing ap status every 30 secs... i.e. mark inactive, eventually removing them... **/ if (t_diff > 30){ update_all_ap_status(); tv_old = tv_new; } if (channel_change) continue; } pthread_mutex_lock(&engine_lock); /** read the packet **/ if (DEBUG) fprintf(stderr,"calling sniff_packet()\n"); sniff_packet(mySettings); if (DEBUG) fprintf(stderr,"returned from sniff_packet()\n"); pthread_mutex_unlock(&engine_lock); } if (DEBUG) fprintf(stderr,"sniffer_engine(): trying to exit...\n"); pthread_mutex_lock(&engine_lock); engine_status = DISABLED; pthread_cond_broadcast(&engine_dead); pthread_mutex_unlock(&engine_lock); pthread_exit(&engine); }