RC YCSBTxnManager::run_txn() { RC rc = RCOK; assert(CC_ALG != CALVIN); if(IS_LOCAL(txn->txn_id) && state == YCSB_0 && next_record_id == 0) { DEBUG("Running txn %ld\n",txn->txn_id); //query->print(); query->partitions_touched.add_unique(GET_PART_ID(0,g_node_id)); } uint64_t starttime = get_sys_clock(); while(rc == RCOK && !is_done()) { rc = run_txn_state(); } uint64_t curr_time = get_sys_clock(); txn_stats.process_time += curr_time - starttime; txn_stats.process_time_short += curr_time - starttime; txn_stats.wait_starttime = get_sys_clock(); if(IS_LOCAL(get_txn_id())) { if(is_done() && rc == RCOK) rc = start_commit(); else if(rc == Abort) rc = start_abort(); } else if(rc == Abort){ rc = abort(); } return rc; }
void next() { _pos++; if (_bci != -1) { // We are not iterating over all handlers... while (!is_done()) { ciExceptionHandler* handler = _method->_exception_handlers[_pos]; if (handler->is_in_range(_bci)) { if (handler->is_catch_all()) { // Found final active catch block. _end = _pos+1; return; } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) { // We cannot do any type analysis here. Must conservatively assume // catch block is reachable. return; } else if (_exception_klass->is_subtype_of(handler->catch_klass())) { // This catch clause will definitely catch the exception. // Final candidate. _end = _pos+1; return; } else if (!_is_exact && handler->catch_klass()->is_subtype_of(_exception_klass)) { // This catch block may be reachable. return; } } // The catch block was not pertinent. Go on. _pos++; } } else { // This is an iteration over all handlers. return; } }
void Task::wait() { boost::mutex::scoped_lock lock(m_mutex); if (is_done()) return; m_cond.wait(lock); }
void AudioHandler::_audio_task() { std::array<int16_t, 512> audioBuffer; while(true) { while(currentCassettes.empty()) xTaskNotifyWait(0, 0, nullptr, portMAX_DELAY); audioBuffer.fill(0); for(uint16_t i=0; i<audioBuffer.size(); i++) { for(auto &c : currentCassettes) audioBuffer[i] += c.get_chunk(); } size_t written_samples = 0; i2s_write(i2s_port, audioBuffer.data(), 1024, &written_samples, portMAX_DELAY); for(auto i=currentCassettes.begin(); i<currentCassettes.end(); i++) { if(i->is_done()) currentCassettes.erase(i); } if(currentCassettes.empty()) i2s_zero_dma_buffer(i2s_port); } }
void test_board_is_done() { Board* board = new_board(3); make_move(board, 6, 'X'); make_move(board, 7, 'X'); make_move(board, 8, 'X'); assert(is_done(board)); destroy_board(board); }
vector<int> preorderTraversal(TreeNode *root) { if (root == NULL) return vector<int>(); set<TreeNode*> done; vector<int> seq; stack<TreeNode*> st; st.push(root); seq.push_back(root->val); while (!st.empty()) { TreeNode *start = st.top(); if (!is_done(start->left, done)) { st.push(start->left); seq.push_back(start->left->val); } else if (!is_done(start->right, done)) { st.push(start->right); seq.push_back(start->right->val); } else { // both left and right are done st.pop(); done.insert(start); } } return seq; }
bool Task::timed_wait(const boost::system_time &until) { boost::mutex::scoped_lock lock(m_mutex); if (is_done()) return true; if (!m_cond.timed_wait(lock, until)) { return false; } return true; }
RingElement *hilb_comp::value() { if (!is_done()) { ERROR("Hilbert function computation not complete"); return 0; } RingElement *result = RingElement::make_raw(R, R->copy(result_poincare)); return result; }
void AxonNode::update(double milli_seconds){ if(is_done()) return; reset_spike_emitter(); if(spike_received()) emit_spike(); reset_received_spikes(); done(); BOOST_FOREACH(Axon* receiver, m_receivers){ receiver->update(milli_seconds); }
RC TPCCTxnManager::run_txn() { #if MODE == SETUP_MODE return RCOK; #endif RC rc = RCOK; uint64_t starttime = get_sys_clock(); #if CC_ALG == CALVIN rc = run_calvin_txn(); return rc; #endif if(IS_LOCAL(txn->txn_id) && (state == TPCC_PAYMENT0 || state == TPCC_NEWORDER0)) { DEBUG("Running txn %ld\n",txn->txn_id); #if DISTR_DEBUG query->print(); #endif query->partitions_touched.add_unique(GET_PART_ID(0,g_node_id)); } while(rc == RCOK && !is_done()) { rc = run_txn_state(); } uint64_t curr_time = get_sys_clock(); txn_stats.process_time += curr_time - starttime; txn_stats.process_time_short += curr_time - starttime; if(IS_LOCAL(get_txn_id())) { if(is_done() && rc == RCOK) rc = start_commit(); else if(rc == Abort) rc = start_abort(); } return rc; }
bool read_pkt(buf_ptr &buf_out) { buf_ptr buf_in = super::buffer(); if (!is_done() && is_partial_complete()) { get_pkt(buf_out); return true; } else if (is_done()) { increment(); return false; } while (true) { super::rlnc_hdr_reserve(buf_in); if (!super::read_pkt(buf_in)) break; if (!validate_type(buf_in)) continue; put_pkt(buf_in); process_rank(); buf_in->reset(); if (is_complete()) { send_ack(super::rlnc_hdr_block(), base::m_coder->rank()); break; } } if (!is_partial_complete()) return false; get_pkt(buf_out); return true; }
void Task::stop() { boost::mutex::scoped_lock lock(m_mutex); lock.unlock(); cancel(); lock.lock(); if (!is_done()) { m_end = time(NULL); m_cond.notify_all(); } m_status = CANCELED; //m_status should always be CANCELED once stop() has been called lock.unlock(); on_cancel(); }
// Get current item AST_Decl * UTL_ScopeActiveIterator::item() { if (is_done()) return NULL; if (stage == UTL_Scope::IK_decls) return iter_source->pd_decls[il]; if (stage == UTL_Scope::IK_localtypes) return iter_source->pd_local_types[il]; return NULL; }
int ciExceptionHandlerStream::count_remaining() { int save_pos = _pos; int save_end = _end; int count = 0; while (!is_done()) { count++; next(); } _pos = save_pos; _end = save_end; return count; }
portBASE_TYPE transceiver::push(int8 c) { if ((m_duplex == HALF_DUPLEX) && (TX_STAT_PROCESSING == m_tx_status)){ return -1; } if (RX_STAT_RECV != m_rx_status){ return -1; } if (m_rx_index >= sizeof(m_rx_buf)){ force_done(); //return -1; } m_rx_buf[m_rx_index++] = c; if (is_done()){ force_done(); } return 0; }
OldAudioController::~OldAudioController() { if (!is_done()) { done(); } PaError rc; //rc = Pa_AbortStream(m_stream); //std::cerr << "AbortStream returns rc=" << rc << ": " << Pa_GetErrorText(rc) << std::endl; //if (rc != paNoError) //{ // std::cerr << "error during AbortStream: " << Pa_GetErrorText(rc) << std::endl; //} rc = Pa_StopStream(m_stream); //is safer but slower std::cerr << "StopStream returns rc=" << rc << ": " << Pa_GetErrorText(rc) << std::endl; if (rc != paNoError) { std::cerr << "Error during StopStream: " << Pa_GetErrorText(rc) << std::endl; } sleep(5); std::cerr << "Closing stream..." << std::endl; rc = Pa_CloseStream(m_stream); //coredump here? std::cerr << "CloseStream returns rc=" << rc << ": " << Pa_GetErrorText(rc) << std::endl; if (rc != paNoError) { std::cerr << "Error during CloseStream: " << Pa_GetErrorText(rc) << std::endl; } //if ( --CONTROLLER_COUNT <= 0 ) //{ // std::cout << "Final AudioController being destroyed, calling terminate" << std::endl; // rc = Pa_Terminate(); // if (rc != paNoError) // { // std::cerr << "error during Terminate: " << Pa_GetErrorText(rc) << std::endl; // } //} }
void YCSBTxnManager::next_ycsb_state() { switch(state) { case YCSB_0: state = YCSB_1; break; case YCSB_1: next_record_id++; if(!IS_LOCAL(txn->txn_id) || !is_done()) { state = YCSB_0; } else { state = YCSB_FIN; } break; case YCSB_FIN: break; default: assert(false); } }
int scan_next() { lex_value = 0; lex_type = NONE; while( !is_done() ) { char c = get_c(); switch( c ) { case '\t': case '\r': case '\n': case ' ': break; case '(': case ')': lex_type = c; break; case '*': lex_type = CLOSURE; break; case '|': lex_type = UNION; break; default: lex_value = c; lex_type = CONCAT; } if( lex_type != NONE ) { return lex_type; } } lex_type = DONE; return DONE; }
// ------------------------------------------------------------------ // ciExceptionHandlerStream::count // // How many exception handlers are there in this stream? // // Implementation note: Compiler2 needs this functionality, so I had int ciExceptionHandlerStream::count() { int save_pos = _pos; int save_end = _end; int count = 0; _pos = -1; _end = _method->_handler_count; next(); while (!is_done()) { count++; next(); } _pos = save_pos; _end = save_end; return count; }
// Called by the requesting thread to send a signal to target thread and // execute "this" callback from the signal handler. int OSThread::Sync_Interrupt_Callback::interrupt(Thread * target, int timeout) { // Let signals to the vm_thread go even if the Threads_lock is not acquired assert(Threads_lock->owned_by_self() || (target == VMThread::vm_thread()), "must have threads lock to call this"); OSThread * osthread = target->osthread(); // may block if target thread already has a pending callback osthread->set_interrupt_callback(this); _target = target; int rslt = thr_kill(osthread->thread_id(), os::Solaris::SIGasync()); assert(rslt == 0, "thr_kill != 0"); bool status = false; jlong t1 = os::javaTimeMillis(); { // don't use safepoint check because we might be the watcher thread. MutexLockerEx ml(_sync, Mutex::_no_safepoint_check_flag); while (!is_done()) { status = _sync->wait(Mutex::_no_safepoint_check_flag, timeout); // status == true if timed out if (status) break; // update timeout jlong t2 = os::javaTimeMillis(); timeout -= t2 - t1; t1 = t2; } } // reset current_callback osthread->remove_interrupt_callback(this); return status; }
RC TPCCTxnManager::send_remote_request() { assert(IS_LOCAL(get_txn_id())); TPCCQuery* tpcc_query = (TPCCQuery*) query; TPCCRemTxnType next_state = TPCC_FIN; uint64_t w_id = tpcc_query->w_id; uint64_t c_w_id = tpcc_query->c_w_id; uint64_t dest_node_id = UINT64_MAX; if(state == TPCC_PAYMENT0) { dest_node_id = GET_NODE_ID(wh_to_part(w_id)); next_state = TPCC_PAYMENT2; } else if(state == TPCC_PAYMENT4) { dest_node_id = GET_NODE_ID(wh_to_part(c_w_id)); next_state = TPCC_FIN; } else if(state == TPCC_NEWORDER0) { dest_node_id = GET_NODE_ID(wh_to_part(w_id)); next_state = TPCC_NEWORDER6; } else if(state == TPCC_NEWORDER8) { dest_node_id = GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id)); /* while(GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id)) != dest_node_id) { msg->items.add(tpcc_query->items[next_item_id++]); } */ if(is_done()) next_state = TPCC_FIN; else next_state = TPCC_NEWORDER6; } else { assert(false); } TPCCQueryMessage * msg = (TPCCQueryMessage*)Message::create_message(this,RQRY); msg->state = state; query->partitions_touched.add_unique(GET_PART_ID(0,dest_node_id)); msg_queue.enqueue(get_thd_id(),msg,dest_node_id); state = next_state; return WAIT_REM; }
void gbres_comp::start_computation() { // int old_compare_type = compare_type; // compare_type = (strategy_flags >> 10); // if (M2_gbTrace >= 4) // { // buffer o; // o << "compare=" << compare_type << newline; // emit(o.str()); // } for (int i=lo_degree; !is_done(); i++) { if (stop_.stop_after_degree && stop_.degree_limit->array[0] < i) { set_status(COMP_DONE_DEGREE_LIMIT); // compare_type = old_compare_type; return; } if (M2_gbTrace >= 1) { buffer o; o << "{" << i << "}"; emit(o.str()); } enum ComputationStatusCode ret = nodes[n_nodes-1]->calc_gens(i+n_nodes-3); if (ret != COMP_DONE) { set_status(ret); // compare_type = old_compare_type; return; } last_completed_degree = i; } // compare_type = old_compare_type; set_status(COMP_DONE); }
void parallel_while_cas_ri(Input& input, const Size_input& size_input, const Fork_input& fork_input, const Set_in_env& set_in_env, const Body& body) { #if defined(SEQUENTIAL_ELISION) parallel_while(input, size_input, fork_input, set_in_env, body); #elif defined(USE_CILK_RUNTIME) && defined(__PASL_CILK_EXT) parallel_while(input, size_input, fork_input, set_in_env, body); #else using request_type = worker_id_t; const request_type Request_blocked = -2; const request_type Request_waiting = -1; using answer_type = enum { Answer_waiting, Answer_transfered }; data::perworker::base<Input> frontier; data::perworker::base<std::atomic<request_type>> request; data::perworker::base<std::atomic<answer_type>> answer; data::perworker::counter::cbase<long> counter; worker_id_t leader_id = threaddag::get_my_id(); msg([&] { std::cout << "leader_id=" << leader_id << std::endl; }); frontier.for_each([&] (worker_id_t, Input& f) { set_in_env(f); }); request.for_each([&] (worker_id_t i, std::atomic<request_type>& r) { request_type t = (i == leader_id) ? Request_waiting : Request_blocked; r.store(t); }); answer.for_each([] (worker_id_t, std::atomic<answer_type>& a) { a.store(Answer_waiting); }); counter.init(0); std::atomic<bool> is_done(false); auto b = [&] { worker_id_t my_id = threaddag::get_my_id(); scheduler_p sched = threaddag::my_sched(); multishot* thread = my_thread(); int nb_workers = threaddag::get_nb_workers(); Input my_frontier; set_in_env(my_frontier); // probably redundant if (my_id == leader_id) { counter++; my_frontier.swap(input); } msg([&] { std::cout << "entering my_id=" << my_id << std::endl; }); long sz; bool init = (my_id != leader_id); while (true) { if (init) { init = false; goto acquire; } // try to perform some local work while (true) { thread->yield(); if (is_done.load()) return; sz = (long)size_input(my_frontier); if (sz == 0) { counter--; msg([&] { std::cout << "decr my_id=" << my_id << " sum=" << counter.sum() << std::endl; }); break; } else { // have some work to do body(my_frontier); // communicate msg([&] { std::cout << "communicate my_id=" << my_id << std::endl; }); request_type req = request[my_id].load(); assert(req != Request_blocked); if (req != Request_waiting) { worker_id_t j = req; if (size_input(my_frontier) > 1) { counter++; msg([&] { std::cout << "transfer from my_id=" << my_id << " to " << j << " sum=" << counter.sum() << std::endl; }); fork_input(my_frontier, frontier[j]); } else { msg([&] { std::cout << "reject from my_id=" << my_id << " to " << j << std::endl; }); } answer[j].store(Answer_transfered); request[my_id].store(Request_waiting); } } } assert(sz == 0); acquire: sz = 0; // reject while (true) { request_type t = request[my_id].load(); if (t == Request_blocked) { break; } else if (t == Request_waiting) { request[my_id].compare_exchange_strong(t, Request_blocked); } else { worker_id_t j = t; request[my_id].compare_exchange_strong(t, Request_blocked); answer[j].store(Answer_transfered); } } // acquire msg([&] { std::cout << "acquire my_id=" << my_id << std::endl; }); while (true) { thread->yield(); if (is_done.load()) return; answer[my_id].store(Answer_waiting); if (my_id == leader_id && counter.sum() == 0) { is_done.store(true); continue; } util::ticks::microseconds_sleep(1.0); if (nb_workers > 1) { worker_id_t id = sched->random_other(); if (request[id].load() == Request_blocked) continue; request_type orig = Request_waiting; bool s = request[id].compare_exchange_strong(orig, my_id); if (! s) continue; while (answer[my_id].load() == Answer_waiting) { thread->yield(); util::ticks::microseconds_sleep(1.0); if (is_done.load()) return; } frontier[my_id].swap(my_frontier); sz = (long)size_input(my_frontier); } if (sz > 0) { msg([&] { std::cout << "received " << sz << " items my_id=" << my_id << std::endl; }); request[my_id].store(Request_waiting); break; } } } msg([&] { std::cout << "exiting my_id=" << my_id << std::endl; }); }; parallel_while(b); #endif }
void test2() { INFO("FAT32", "Remounting disk."); CHECKSERT(not disk->empty(), "Disk not empty"); CHECKSERT(disk->dev().size() == SIZE / 512, "Disk size is %llu bytes", SIZE); disk->init_fs(disk->MBR, [] (fs::error_t err, auto& fs) { CHECKSERT(not err, "Filesystem mounted on VBR1"); fs.stat(shallow_banana, [] (auto err, const auto& ent) { INFO("FAT32", "Shallow banana"); CHECKSERT(not err, "Stat %s", shallow_banana.c_str()); CHECKSERT(ent.is_valid(), "Stat file in root dir"); CHECKSERT(ent.is_file(), "Entity is file"); CHECKSERT(!ent.is_dir(), "Entity is not directory"); CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'"); is_done(); }); fs.read_file(shallow_banana, [] (fs::error_t err, fs::buffer_t buf) { INFO("FAT32", "Read file"); if (err) { printf("Read error: %s\n", err.to_string().c_str()); } CHECKSERT(not err, "read_file: Read %s asynchronously", shallow_banana.c_str()); printf("%s\n", internal_banana.c_str()); std::string banana((const char*) buf->data(), buf->size()); CHECKSERT(banana == internal_banana, "Correct shallow banana"); is_done(); }); fs.stat(deep_banana, [] (auto err, const auto& ent) { INFO("FAT32", "Deep banana"); auto& fs = disk->fs(); CHECKSERT(not err, "Stat %s", deep_banana.c_str()); CHECKSERT(ent.is_valid(), "Stat file in deep dir"); CHECKSERT(ent.is_file(), "Entity is file"); CHECKSERT(!ent.is_dir(), "Entity is not directory"); CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'"); // asynch file reading test fs.read(ent, 0, ent.size(), [] (fs::error_t err, fs::buffer_t buf) { INFO("FAT32", "Read inside stat"); CHECKSERT(not err, "read: Read %s asynchronously", deep_banana.c_str()); std::string banana((const char*) buf->data(), buf->size()); CHECKSERT(banana == internal_banana, "Correct deep fried banana"); is_done(); }); }); }); }
void TPCCTxnManager::next_tpcc_state() { //TPCCQuery* tpcc_query = (TPCCQuery*) query; switch(state) { case TPCC_PAYMENT_S: state = TPCC_PAYMENT0; break; case TPCC_PAYMENT0: state = TPCC_PAYMENT1; break; case TPCC_PAYMENT1: state = TPCC_PAYMENT2; break; case TPCC_PAYMENT2: state = TPCC_PAYMENT3; break; case TPCC_PAYMENT3: state = TPCC_PAYMENT4; break; case TPCC_PAYMENT4: state = TPCC_PAYMENT5; break; case TPCC_PAYMENT5: state = TPCC_FIN; break; case TPCC_NEWORDER_S: state = TPCC_NEWORDER0; break; case TPCC_NEWORDER0: state = TPCC_NEWORDER1; break; case TPCC_NEWORDER1: state = TPCC_NEWORDER2; break; case TPCC_NEWORDER2: state = TPCC_NEWORDER3; break; case TPCC_NEWORDER3: state = TPCC_NEWORDER4; break; case TPCC_NEWORDER4: state = TPCC_NEWORDER5; break; case TPCC_NEWORDER5: if(!IS_LOCAL(txn->txn_id) || !is_done()) { state = TPCC_NEWORDER6; } else { state = TPCC_FIN; } break; case TPCC_NEWORDER6: // loop pt 1 state = TPCC_NEWORDER7; break; case TPCC_NEWORDER7: state = TPCC_NEWORDER8; break; case TPCC_NEWORDER8: // loop pt 2 state = TPCC_NEWORDER9; break; case TPCC_NEWORDER9: ++next_item_id; if(!IS_LOCAL(txn->txn_id) || !is_done()) { state = TPCC_NEWORDER6; } else { state = TPCC_FIN; } break; case TPCC_FIN: break; default: assert(false); } }
void BRenderThread::run() { while(!is_done(1)) { BRenderCommand *new_command = 0; thread_lock->lock("BRenderThread::run 1"); // Got new command if(command_queue) { ; } else // Wait for new command { thread_lock->unlock(); input_lock->lock("BRenderThread::run 2"); thread_lock->lock("BRenderThread::run 3"); } // Pull the command off if(!is_done(0)) { new_command = command_queue; command_queue = 0; } thread_lock->unlock(); // Process the command here to avoid delay. // Quit condition if(!new_command) { ; } else if(new_command->command == BRenderCommand::BRENDER_STOP) { stop(); delete new_command; new_command = 0; // if(command) delete command; // command = new_command; } else if(new_command->command == BRenderCommand::BRENDER_RESTART) { // Compare EDL's and get last equivalent position in new EDL if(command && command->edl) new_command->position = new_command->edl->equivalent_output(command->edl); else new_command->position = 0; stop(); //printf("BRenderThread::run 4\n"); brender->completion_lock->lock("BRenderThread::run 4"); //printf("BRenderThread::run 5\n"); if(new_command->edl->tracks->total_playable_vtracks()) { if(command) delete command; command = new_command; //printf("BRenderThread::run 6\n"); start(); //printf("BRenderThread::run 7\n"); } else { //printf("BRenderThread::run 8 %p\n", farm_server); delete new_command; new_command = 0; } } } }
void parse_wps_settings(const u_char *packet, struct pcap_pkthdr *header, char *target, int passive, int mode, int source) { struct radio_tap_header *rt_header = NULL; struct dot11_frame_header *frame_header = NULL; struct libwps_data *wps = NULL; enum encryption_type encryption = NONE; char *bssid = NULL, *ssid = NULL, *lock_display = NULL; int wps_parsed = 0, probe_sent = 0, channel = 0, rssi = 0; static int channel_changed = 0; char info_manufac[500]; char info_modelnum[500]; char info_modelserial[500]; wps = malloc(sizeof(struct libwps_data)); memset(wps, 0, sizeof(struct libwps_data)); if(packet == NULL || header == NULL || header->len < MIN_BEACON_SIZE) { goto end; } rt_header = (struct radio_tap_header *) radio_header(packet, header->len); frame_header = (struct dot11_frame_header *) (packet + rt_header->len); /* If a specific BSSID was specified, only parse packets from that BSSID */ if(!is_target(frame_header)) { goto end; } set_ssid(NULL); bssid = (char *) mac2str(frame_header->addr3, ':'); set_bssid((unsigned char *) frame_header->addr3); if(bssid) { if((target == NULL) || (target != NULL && strcmp(bssid, target) == 0)) { channel = parse_beacon_tags(packet, header->len); rssi = signal_strength(packet, header->len); ssid = (char *) get_ssid(); if(target != NULL && channel_changed == 0) { ualarm(0, 0); change_channel(channel); channel_changed = 1; } if(frame_header->fc.sub_type == PROBE_RESPONSE || frame_header->fc.sub_type == SUBTYPE_BEACON) { wps_parsed = parse_wps_parameters(packet, header->len, wps); } if(!is_done(bssid) && (get_channel() == channel || source == PCAP_FILE)) { if(frame_header->fc.sub_type == SUBTYPE_BEACON && mode == SCAN && !passive && should_probe(bssid)) { send_probe_request(get_bssid(), get_ssid()); probe_sent = 1; } if(!insert(bssid, ssid, wps, encryption, rssi)) { update(bssid, ssid, wps, encryption); } else if(wps->version > 0) { switch(wps->locked) { case WPSLOCKED: lock_display = YES; break; case UNLOCKED: case UNSPECIFIED: lock_display = NO; break; } //ideas made by kcdtv if(get_chipset_output == 1) //if(1) { if (c_fix == 0) { //no use a fixed channel cprintf(INFO,"Option (-g) REQUIRES a channel to be set with (-c)\n"); exit(0); } FILE *fgchipset=NULL; char cmd_chipset[4000]; char cmd_chipset_buf[4000]; char buffint[5]; char *aux_cmd_chipset=NULL; memset(cmd_chipset, 0, sizeof(cmd_chipset)); memset(cmd_chipset_buf, 0, sizeof(cmd_chipset_buf)); memset(info_manufac, 0, sizeof(info_manufac)); memset(info_modelnum, 0, sizeof(info_modelnum)); memset(info_modelserial, 0, sizeof(info_modelserial)); strcat(cmd_chipset,"reaver -0 -s y -vv -i "); //need option to stop reaver in m1 stage strcat(cmd_chipset,get_iface()); strcat(cmd_chipset, " -b "); strcat(cmd_chipset, mac2str(get_bssid(),':')); strcat(cmd_chipset," -c "); snprintf(buffint, sizeof(buffint), "%d",channel); strcat(cmd_chipset, buffint); //cprintf(INFO,"\n%s\n",cmd_chipset); if ((fgchipset = popen(cmd_chipset, "r")) == NULL) { printf("Error opening pipe!\n"); //return -1; } while (fgets(cmd_chipset_buf, 4000, fgchipset) != NULL) { //[P] WPS Manufacturer: xxx //[P] WPS Model Number: yyy //[P] WPS Model Serial Number: zzz //cprintf(INFO,"\n%s\n",cmd_chipset_buf); aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Manufacturer:"); if(aux_cmd_chipset != NULL) { //bug fix by alxchk strncpy(info_manufac, aux_cmd_chipset+21, sizeof(info_manufac)); } aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Model Number:"); if(aux_cmd_chipset != NULL) { //bug fix by alxchk strncpy(info_modelnum, aux_cmd_chipset+21, sizeof(info_modelnum)); } aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Model Serial Number:"); if(aux_cmd_chipset != NULL) { //bug fix by alxchk strncpy(info_modelserial, aux_cmd_chipset+28, sizeof(info_modelserial)); } } //cprintf(INFO,"\n%s\n",info_manufac); info_manufac[strcspn ( info_manufac, "\n" )] = '\0'; info_modelnum[strcspn ( info_modelnum, "\n" )] = '\0'; info_modelserial[strcspn ( info_modelserial, "\n" )] = '\0'; if(pclose(fgchipset)) { //printf("Command not found or exited with error status\n"); //return -1; } } if (o_file_p == 0) { cprintf(INFO, "%17s %2d %.2d %d.%d %s %s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid); } else { if(get_chipset_output == 1) { cprintf(INFO, "%17s|%2d|%.2d|%d.%d|%s|%s|%s|%s|%s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid, info_manufac, info_modelnum, info_modelserial); }else { cprintf(INFO, "%17s|%2d|%.2d|%d.%d|%s|%s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid); } }
zz_packet_outcome zz_process_packet(zz_handler *zz, zz_mac_addr station, zz_mac_addr bssid, const struct pcap_pkthdr *packet_header, const struct ieee8021x_authentication_header *auth) { zz_client *client; time_t last_data_ts; zz_packet_outcome outcome = {0}; /* create or fetch the client descriptor */ if (zz_clients_lookup(&zz->clients, station, bssid, &client)) { /* surely attempt to track the client if new */ outcome.new_client = 1; } /* keep track of the last seen data packet */ last_data_ts = client->last_data_ts; client->last_data_ts = packet_header->ts.tv_sec; /* this is an authentication message */ if (auth) { unsigned handshake_id; uint64_t ts; uint64_t replay_counter_1; /* expected replay counter of the first */ int initialize = 0; /* compute the timestamp */ ts = (packet_header->ts.tv_sec * 1000000 + packet_header->ts.tv_usec % 1000000); /* try to guess the handshake number */ if ((be16toh(auth->flags) & ZZ_EAPOL_MASK_1) == ZZ_EAPOL_FLAGS_1) { handshake_id = 0; replay_counter_1 = be64toh(auth->replay_counter); } else if ((be16toh(auth->flags) & ZZ_EAPOL_MASK_2) == ZZ_EAPOL_FLAGS_2) { handshake_id = 1; replay_counter_1 = be64toh(auth->replay_counter); } else if ((be16toh(auth->flags) & ZZ_EAPOL_MASK_3) == ZZ_EAPOL_FLAGS_3) { handshake_id = 2; replay_counter_1 = be64toh(auth->replay_counter) - 1; } else if ((be16toh(auth->flags) & ZZ_EAPOL_MASK_4) == ZZ_EAPOL_FLAGS_4) { handshake_id = 3; replay_counter_1 = be64toh(auth->replay_counter) - 1; } else { #ifdef DEBUG zz_log("Unrecognizable EAPOL flags 0x%04hx", be16toh(auth->flags)); #endif outcome.ignore = 1; outcome.ignore_reason = ZZ_IGNORE_REASON_INVALID_EAPOL; return outcome; } outcome.handshake_info = handshake_id + 1; /* initialize after the first handshake message ever */ if (!client->handshake) { initialize = 1; outcome.track_reason = ZZ_TRACK_REASON_FIRST_HANDSHAKE; } /* reinitialize after too much time passed since the last one (even if * this is a retransmission) */ else if (abs(client->last_handshake_ts, ts) > ZZ_MAX_HANDSHAKE_TIME) { initialize = 1; outcome.track_reason = ZZ_TRACK_REASON_EXPIRATION; } /* if already received this message */ else if (client->handshake & (1 << handshake_id)) { /* if this is a retransmission or the one saved was, ignore it */ if (memcmp(&client->headers[handshake_id], auth, sizeof(struct ieee8021x_authentication_header)) == 0) { outcome.ignore = 1; outcome.ignore_reason = ZZ_IGNORE_REASON_RETRANSMISSION; return outcome; } /* otherwise reinitialize */ else { initialize = 1; outcome.track_reason = ZZ_TRACK_REASON_INVALIDATION; } } /* if first time received this message (handshake in progress) */ else { int ok; /* check the replay counter */ switch (handshake_id) { case 0: case 1: ok = (be64toh(auth->replay_counter) == client->replay_counter); break; case 2: case 3: ok = (be64toh(auth->replay_counter) == client->replay_counter + 1); break; } if (!ok) { outcome.ignore = 1; outcome.ignore_reason = ZZ_IGNORE_REASON_INVALID_COUNTER; return outcome; } /* store the message */ client->handshake |= 1 << handshake_id; memcpy(&client->headers[handshake_id], auth, sizeof(struct ieee8021x_authentication_header)); /* if this is the last needed message */ if (handshake_id < zz->setup.max_handshake && is_done(client->handshake, zz->setup.max_handshake)) { outcome.got_handshake = 1; } } /* if (re)initialization has been triggered */ if (initialize) { outcome.grace_time = 1; /* handshake detected */ outcome.track_client = 1; client->last_handshake_ts = ts; client->replay_counter = replay_counter_1; client->handshake = 1 << handshake_id; memcpy(&client->headers[handshake_id], auth, sizeof(struct ieee8021x_authentication_header)); } } /* this is a data packet */ else { /* notify if traffic is detected again after "long" time so if the killer * gave up it can restart the deauthentication process; the "long" time * is set to the killer "giveup time" */ if (last_data_ts && !is_done(client->handshake, zz->setup.max_handshake) && (packet_header->ts.tv_sec - last_data_ts > (zz->setup.killer_max_attempts - 1) * zz->setup.killer_interval)) { outcome.track_client = 1; outcome.track_reason = ZZ_TRACK_REASON_ALIVE; } } /* dump valid eapol messages and data for completed (according to max) clients */ if (auth || is_done(client->handshake, zz->setup.max_handshake)) { outcome.dump_packet = 1; } return outcome; }
void parse_wps_settings(const u_char *packet, struct pcap_pkthdr *header, char *target, int passive, int mode, int source) { struct radio_tap_header *rt_header = NULL; struct dot11_frame_header *frame_header = NULL; struct libwps_data *wps = NULL; enum encryption_type encryption = NONE; char *bssid = NULL, *ssid = NULL, *lock_display = NULL; int wps_parsed = 0, probe_sent = 0, channel = 0, rssi = 0; static int channel_changed = 0; wps = malloc(sizeof(struct libwps_data)); memset(wps, 0, sizeof(struct libwps_data)); if(packet == NULL || header == NULL || header->len < MIN_BEACON_SIZE) { goto end; } rt_header = (struct radio_tap_header *) radio_header(packet, header->len); frame_header = (struct dot11_frame_header *) (packet + rt_header->len); /* If a specific BSSID was specified, only parse packets from that BSSID */ if(!is_target(frame_header)) { goto end; } set_ssid(NULL); bssid = (char *) mac2str(frame_header->addr3, ':'); if(bssid) { if((target == NULL) || (target != NULL && strcmp(bssid, target) == 0)) { channel = parse_beacon_tags(packet, header->len); rssi = signal_strength(packet, header->len); ssid = (char *) get_ssid(); if(target != NULL && channel_changed == 0) { ualarm(0, 0); change_channel(channel); channel_changed = 1; } if(frame_header->fc.sub_type == PROBE_RESPONSE || frame_header->fc.sub_type == SUBTYPE_BEACON) { wps_parsed = parse_wps_parameters(packet, header->len, wps); } if(!is_done(bssid) && (get_channel() == channel || source == PCAP_FILE || !get_channel())) { if(frame_header->fc.sub_type == SUBTYPE_BEACON && mode == SCAN && !passive && should_probe(bssid)) { send_probe_request(get_bssid(), get_ssid()); probe_sent = 1; } if(!insert(bssid, ssid, wps, encryption, rssi)) { update(bssid, ssid, wps, encryption); } else if(wps->version > 0) { switch(wps->locked) { case WPSLOCKED: lock_display = YES; break; case UNLOCKED: case UNSPECIFIED: lock_display = NO; break; } cprintf(INFO, "%17s %2d %.2d %d.%d %s %s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid); } if(probe_sent) { update_probe_count(bssid); } /* * If there was no WPS information, then the AP does not support WPS and we should ignore it from here on. * If this was a probe response, then we've gotten all WPS info we can get from this AP and should ignore it from here on. */ if(!wps_parsed || frame_header->fc.sub_type == PROBE_RESPONSE) { mark_ap_complete(bssid); } } } /* Only update received signal strength if we are on the same channel as the AP, otherwise power measurements are screwy */ if(channel == get_channel()) { update_ap_power(bssid, rssi); } free(bssid); bssid = NULL; }
void quit_game(int sig) { is_done(); _exit(1); }