?? mac-802_11.cc
字號:
voidMac802_11::rx_resume(){ assert(pktRx_ == 0); assert(mhRecv_.busy() == 0); SET_RX_STATE(MAC_IDLE);}/* ====================================================================== Timer Handler Routines ====================================================================== */voidMac802_11::backoffHandler(){ if(pktCTRL_) { assert(mhSend_.busy() || mhDefer_.busy()); return; } // wqos - Fri 13 Oct 00, 09:03 - dugdale if(check_pktPCF() == 0) return; // wqos - changes by dugdale ends if(check_pktRTS() == 0) return; if(check_pktTx() == 0) return;}voidMac802_11::deferHandler(){// wqos - Sat 18 Aug 01, 13:14 - dugdale assert(pktCTRL_ || pktRTS_ || pktTx_ || pktPCF_);// wqos - changes by dugdale ends if(check_pktCTRL() == 0) return; // wqos - Sat 18 Aug 01, 13:15 - dugdale if(check_pktPCF() == 0) return; // wqos - changes by dugdale ends // wqos - Sat 06 Jan 01, 15:22 - dugdale // REMOVE THIS LATER!!!!! //if(mhBackoff_.busy()) // mhBackoff_.stop(); // Let's see if it works with the above commented out. // wqos - changes by dugdale ends assert(mhBackoff_.busy() == 0); //if (mhBackoff_.busy() != 0) //{ // printf("deferHandler:mhBackoff_ busy!\n"); // return; //} if(check_pktRTS() == 0) return; if(check_pktTx() == 0) return;}voidMac802_11::navHandler(){ // wqos - Fri 06 Oct 00, 11:38 - dugdale // If this is the PC, and we have had a CFP, end it now if(!pc_&&cfp_) cfp_=0; // wqos - changes by dugdale ends if(is_idle() && mhBackoff_.paused()) mhBackoff_.resume(difs_);}voidMac802_11::recvHandler(){ recv_timer();}voidMac802_11::sendHandler(){ send_timer();}voidMac802_11::txHandler(){ tx_active_ = 0;}// wqos - Tue 26 Sep 00, 16:49 - dugdalevoidMac802_11::beaconHandler(){ // Schedule the next beacon mhBeacon_.start(macmib_->dot11BeaconPeriod*0.001024); // Send the beacon send_beacon();}voidMac802_11::pcfHandler(){ if(pc_) { // Send CFEnd frame cfp_=0; } else { set_nav(macmib_->dot11CFPMaxDuration); }}// wqos - changes by dugdale ends/* ====================================================================== The "real" Timer Handler Routines ====================================================================== */voidMac802_11::send_timer(){ switch(tx_state_) { /* * Sent a RTS, but did not receive a CTS. */ case MAC_RTS: RetransmitRTS(); break; /* * Sent a CTS, but did not receive a DATA packet. */ case MAC_CTS: assert(pktCTRL_); Packet::free(pktCTRL_); pktCTRL_ = 0; break; /* * Sent DATA, but did not receive an ACK packet. */ case MAC_SEND: RetransmitDATA(); break; /* * Sent an ACK, and now ready to resume transmission. */ case MAC_ACK: assert(pktCTRL_); Packet::free(pktCTRL_); pktCTRL_ = 0; // wqos - Wed 08 Nov 00, 14:43 - dugdale // If we are a base station and this is during a CFP we want to send a // CFPoll or CFEnd frame if(cfp_&&pc_) { // Check if there is time left on the CFP and if there are polls left to send if((Scheduler::instance().clock()<lastPoll_)&&pollsToSend_) { pollsToSend_--; sendPoll(); } else { sendCFEnd(); } } // wqos - changes by dugdale ends break; // wqos - Thu 26 Oct 00, 16:14 - dugdale case MAC_BEACONING: if(pktPCF_) { Packet::free(pktPCF_); pktPCF_ = 0; } if(cfp_) { // Now we have sent the beacon and should start the CFP do_cfp(); } break; // wqos - changes by dugdale ends // wqos - Tue 10 Oct 00, 14:52 - dugdale case MAC_POLLING: fprintf(stderr, "Poll timed out!!!\n"); Packet::free(pktPCF_); pktPCF_ = 0; // Check if there is time left on the CFP and if there are polls left to send if((Scheduler::instance().clock()<lastPoll_)&&pollsToSend_) { pollsToSend_--; sendPoll(); } else { sendCFEnd(); } break; // wqos - changes by dugdale ends case MAC_IDLE: break; default: assert(0); } tx_resume();}/* ====================================================================== Outgoing Packet Routines ====================================================================== */intMac802_11::check_pktCTRL(){ struct hdr_mac802_11 *mh; double timeout; if(pktCTRL_ == 0) return -1; if(tx_state_ == MAC_CTS || tx_state_ == MAC_ACK) return -1; mh = HDR_MAC802_11(pktCTRL_); switch(mh->dh_fc.fc_subtype) { /* * If the medium is not IDLE, don't send the CTS. */ case MAC_Subtype_CTS: if(!is_idle()) { discard(pktCTRL_, DROP_MAC_BUSY); pktCTRL_ = 0; return 0; } SET_TX_STATE(MAC_CTS); timeout = (mh->dh_duration * 1e-6) + CTS_Time; // XXX break; /* * IEEE 802.11 specs, section 9.2.8 * Acknowledments are sent after an SIFS, without regard to * the busy/idle state of the medium. */ case MAC_Subtype_ACK: SET_TX_STATE(MAC_ACK); timeout = ACK_Time; break; default: fprintf(stderr, "check_pktCTRL:Invalid MAC Control subtype\n"); exit(1); } TRANSMIT(pktCTRL_, timeout); return 0;}intMac802_11::check_pktRTS(){ struct hdr_mac802_11 *mh; double timeout; assert(mhBackoff_.busy() == 0); if(pktRTS_ == 0) return -1; //struct hdr_cmn *ch = HDR_CMN(pktRTS_); mh = HDR_MAC802_11(pktRTS_); switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_RTS: if(! is_idle()) { inc_cw(); mhBackoff_.start(cw_, is_idle()); return 0; } SET_TX_STATE(MAC_RTS); timeout = CTSTimeout; break; default: fprintf(stderr, "check_pktRTS:Invalid MAC Control subtype\n"); exit(1); } TRANSMIT(pktRTS_, timeout); return 0;}intMac802_11::check_pktTx(){ struct hdr_mac802_11 *mh; double timeout; assert(mhBackoff_.busy() == 0); if(pktTx_ == 0) return -1; mh = HDR_MAC802_11(pktTx_); int len = HDR_CMN(pktTx_)->size(); switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_Data: // wqos - Thu 30 Nov 00, 15:06 - dugdale if(! is_idle()&&!cfp_) { // wqos - changes by dugdale ends sendRTS(ETHER_ADDR(mh->dh_da)); inc_cw(); mhBackoff_.start(cw_, is_idle()); return 0; } SET_TX_STATE(MAC_SEND); if((u_int32_t)ETHER_ADDR(mh->dh_da) != MAC_BROADCAST) //timeout = ACKTimeout(netif_->txtime(pktTx_))+5; // why 10 ? buggy //timeout = ACKTimeout(len) + 10; timeout = ACKTimeout(len); else timeout = TX_Time(pktTx_); break; default: fprintf(stderr, "check_pktTx:Invalid MAC Control subtype\n"); //printf("pktRTS:%x, pktCTS/ACK:%x, pktTx:%x\n",pktRTS_, pktCTRL_,pktTx_); exit(1); } TRANSMIT(pktTx_, timeout); return 0;}// wqos - Tue 10 Oct 00, 14:11 - dugdale intMac802_11::check_pktPCF(){ struct hdr_mac802_11 *mh; double timeout; // assert(mhBackoff_.busy() == 0); if(pktPCF_ == 0) return -1; mh = HDR_MAC802_11(pktPCF_); int len = HDR_CMN(pktPCF_)->size(); switch(mh->dh_fc.fc_type) { case MAC_Type_Data: switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_CFPoll: fprintf(stderr,"Sent poll to %d at time %f\n",ETHER_ADDR(mh->dh_da), (Scheduler::instance()).clock()); // The polled station should respond within a PIFS timeout = TX_Time(pktPCF_)+pifs_; SET_TX_STATE(MAC_POLLING); break; } break; case MAC_Type_Control: switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_CFEnd: if(! is_idle()) { return -1; inc_cw(); mhBackoff_.start(cw_, is_idle()); return 0; } timeout = TX_Time(pktPCF_); SET_TX_STATE(MAC_BEACONING); // HMMM... CHANGE!!! break; } break; case MAC_Type_Management: switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_Beacon: // if(tx_state_ != MAC_IDLE) if(!is_idle()) return -1; struct beacon_frame *beacon = (struct beacon_frame *)pktPCF_->access(hdr_mac::offset_); timeout = TX_Time(pktPCF_); // Check if this beacon starts a CFP if(beacon->bf_cfparamset.CFPCount == 0) cfp_ = 1; // CFP... fprintf(stderr, "Really sent beacon at %f\n", Scheduler::instance().clock()); SET_TX_STATE(MAC_BEACONING); } break; default: fprintf(stderr, "check_pktPCF:Invalid MAC (sub)type\n"); exit(1); } TRANSMIT(pktPCF_, timeout); return 0;}// wqos - changes by dugdale ends/* * Low-level transmit functions that actually place the packet onto * the channel. */voidMac802_11::sendRTS(int dst){ Packet *p = Packet::alloc(); hdr_cmn* ch = HDR_CMN(p); struct rts_frame *rf = (struct rts_frame*)p->access(hdr_mac::offset_); assert(pktTx_); assert(pktRTS_ == 0); /* * If the size of the packet is larger than the * RTSThreshold, then perform the RTS/CTS exchange. * * XXX: also skip if destination is a broadcast */ if( (u_int32_t) HDR_CMN(pktTx_)->size() < macmib_->RTSThreshold || (u_int32_t) dst == MAC_BROADCAST) { Packet::free(p); //p = 0; return; } ch->uid() = 0; ch->ptype() = PT_MAC; ch->size() = ETHER_RTS_LEN; ch->iface() = -2; ch->error() = 0; bzero(rf, MAC_HDR_LEN); rf->rf_fc.fc_protocol_version = MAC_ProtocolVersion; rf->rf_fc.fc_type = MAC_Type_Control; rf->rf_fc.fc_subtype = MAC_Subtype_RTS; rf->rf_fc.fc_to_ds = 0; rf->rf_fc.fc_from_ds = 0; rf->rf_fc.fc_more_frag = 0; rf->rf_fc.fc_retry = 0; rf->rf_fc.fc_pwr_mgt = 0; rf->rf_fc.fc_more_data = 0; rf->rf_fc.fc_wep = 0; rf->rf_fc.fc_order = 0; rf->rf_duration = RTS_DURATION(pktTx_); //ETHER_ADDR(rf->rf_ra) = dst; STORE4BYTE(&dst, (rf->rf_ra)); //ETHER_ADDR(rf->rf_ta) = index_; STORE4BYTE(&index_, (rf->rf_ta)); pktRTS_ = p;}voidMac802_11::sendCTS(int dst, double rts_duration){ Packet *p = Packet::alloc(); hdr_cmn* ch = HDR_CMN(p); struct cts_frame *cf = (struct cts_frame*)p->access(hdr_mac::offset_); assert(pktCTRL_ == 0); ch->uid() = 0; ch->ptype() = PT_MAC; ch->size() = ETHER_CTS_LEN; ch->iface() = -2; ch->error() = 0; //ch->direction() = hdr_cmn::DOWN; bzero(cf, MAC_HDR_LEN); cf->cf_fc.fc_protocol_version = MAC_ProtocolVersion; cf->cf_fc.fc_type = MAC_Type_Control; cf->cf_fc.fc_subtype = MAC_Subtype_CTS; cf->cf_fc.fc_to_ds = 0; cf->cf_fc.fc_from_ds = 0; cf->cf_fc.fc_more_frag = 0; cf->cf_fc.fc_retry = 0; cf->cf_fc.fc_pwr_mgt = 0; cf->cf_fc.fc_more_data = 0; cf->cf_fc.fc_wep = 0; cf->cf_fc.fc_order = 0; cf->cf_duration = CTS_DURATION(rts_duration); //ETHER_ADDR(cf->cf_ra) = dst; STORE4BYTE(&dst, (cf->cf_ra)); //STORE4BYTE(&dst, (mh->dh_da)); pktCTRL_ = p; }voidMac802_11::sendACK(int dst){ Packet *p = Packet::alloc(); hdr_cmn* ch = HDR_CMN(p); struct ack_frame *af = (struct ack_frame*)p->access(hdr_mac::offset_); assert(pktCTRL_ == 0); ch->uid() = 0; ch->ptype() = PT_MAC; ch->size() = ETHER_ACK_LEN; ch->iface() = -2; ch->error() = 0; bzero(af, MAC_HDR_LEN); af->af_fc.fc_protocol_version = MAC_ProtocolVersion; af->af_fc.fc_type = MAC_Type_Control; af->af_fc.fc_subtype = MAC_Subtype_ACK; af->af_fc.fc_to_ds = 0; af->af_fc.fc_from_ds = 0; af->af_fc.fc_more_frag = 0; af->af_fc.fc_retry = 0; af->af_fc.fc_pwr_mgt = 0; af->af_fc.fc_more_data = 0; af->af_fc.fc_wep = 0; af->af_fc.fc_order = 0; af->af_duration = ACK_DURATION(); //ETHER_ADDR(af->af_ra) = dst; STORE4BYTE(&dst, (af->af_ra)); pktCTRL_ = p;}voidMac802_11::sendDATA(Packet *p){ hdr_cmn* ch = HDR_CMN(p); struct hdr_mac802_11* dh = HDR_MAC802_11(p); assert(pktTx_ == 0); /* * Update the MAC header */ ch->size() += ETHER_HDR_LEN; dh->dh_fc.fc_protocol_version = MAC_ProtocolVersion; dh->dh_fc.fc_type = MAC_Type_Data; dh->dh_fc.fc_subtype = MAC_Subtype_Data; //printf(".....p = %x, mac-subtype-%d\n",p,dh->dh_fc.fc_subtype); dh->dh_fc.fc_to_ds = 0; dh->dh_fc.fc_from_ds = 0; dh->dh_fc.fc_more_frag = 0; dh->dh_fc.fc_retry = 0; dh->dh_fc.fc_pwr_mgt = 0; dh->dh_fc.fc_more_data = 0; dh->dh_fc.fc_wep = 0; dh->dh_fc.fc_order = 0; if((u_int32_t)ETHER_ADDR(dh->dh_da) != MAC_BROADCAST) dh->dh_duration = DATA_DURATION(); else dh->dh_duration = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -