⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcf_support-2.1b8.patch

📁 用c++实现的802.11中的pcf功能的源代码
💻 PATCH
📖 第 1 页 / 共 4 页
字号:
+		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.@@ -1034,6 +1306,20 @@ 		hdr->error() = 1; 	} +	// wqos - Fri 03 Nov 00, 17:45 - dugdale+	if(pc_&&tx_state_ == MAC_POLLING) {++		// Why is this done here?????????? Check!++		// Might not be so good++		+		//		fprintf(stderr, "Nils@%f!!! %x %x\n",Scheduler::instance().clock(),mh->dh_fc.fc_type,mh->dh_fc.fc_subtype);+		if(mhSend_.busy())+			mhSend_.stop();+	}+	// wqos - changes by dugdale ends+	 	if(rx_state_ == MAC_IDLE) { 		SET_RX_STATE(MAC_RECV); 		pktRx_ = p;@@ -1063,6 +1349,9 @@ 	u_int32_t src;  	hdr_cmn *ch = HDR_CMN(pktRx_); 	hdr_mac802_11 *mh = HDR_MAC802_11(pktRx_);+	// wqos - Thu 05 Oct 00, 14:03 - dugdale +	struct beacon_frame *beacon;+	// wqos - changes by dugdale ends 	u_int32_t dst = ETHER_ADDR(mh->dh_da); 	// XXX debug 	//struct cts_frame *cf = (struct cts_frame*)pktRx_->access(hdr_mac::offset_);@@ -1110,8 +1399,17 @@ 	 *	- update the NAV (Network Allocation Vector) 	 */ 	if(dst != (u_int32_t)index_) {-		set_nav(mh->dh_duration);-	}+		// wqos - Wed 29 Nov 00, 13:07 - dugdale +		// Detect CFP even if the beacon was lost...+		if(mh->dh_duration==32768&&!cfp_) {+			cfp_=1;+			//set_nav(macmib_->dot11CFPMaxDuration);+			set_nav((u_int32_t)(macmib_->dot11CFPMaxDuration*0.001024*1000000));+		} else if(!cfp_) {+			set_nav(mh->dh_duration);+		}+		// wqos - changes by dugdale ends+    	}          /* tap out - */         if (tap_ && type == MAC_Type_Data &&@@ -1144,12 +1442,48 @@ 	switch(type) {  	case MAC_Type_Management:-		discard(pktRx_, DROP_MAC_PACKET_ERROR);+		// wqos - Tue 03 Oct 00, 16:42 - dugdale+		switch(subtype) {+		case MAC_Subtype_Beacon:+			beacon = (struct beacon_frame *)pktRx_->access(hdr_mac::offset_);++			// Set these values received from the PC in the MACMIB+			macmib_->dot11CFPPeriod      = beacon->bf_cfparamset.CFPPeriod;+			macmib_->dot11CFPMaxDuration = beacon->bf_cfparamset.CFPMaxDuration;+			macmib_->dot11BeaconPeriod   = beacon->bf_binterval;+			macmib_->dot11DTIMPeriod     = beacon->bf_tim.DTIMperiod;+			+			if(beacon->bf_cfparamset.CFPCount==0) {+				// A CFP starts here+				cfp_=1;+				fprintf(stderr,"CFP started at time %f... Duration %f\n",(Scheduler::instance()).clock(), tutos(beacon->bf_cfparamset.CFPMaxDuration));+				// Set the NAV to the maximum length of the CFP+				set_nav((u_int32_t)(beacon->bf_cfparamset.CFPMaxDuration*0.001024*1000000));+				// Set the PCF Timer++				// Should we really stop these timers??? Maybe just pause them...+				//				if(mhBackoff_.busy() && !mhBackoff_.paused())+				if(mhBackoff_.busy())+					//mhBackoff_.pause();+					mhBackoff_.stop();+				if(mhSend_.busy())+					mhSend_.stop();+			}+				// We should set a timer to expire the next TBTT to know when+				// the next CFP should start, but that is not implemented yet+			+				// Do something else here...+			mac_log(pktRx_);+			break;+		default:+			discard(pktRx_, DROP_MAC_PACKET_ERROR);+		}+		// wqos - changes by dugdale ends 		goto done; 		break;--	case MAC_Type_Control:-		switch(subtype) {+		+		case MAC_Type_Control:+			switch(subtype) { 		case MAC_Subtype_RTS: 			recvRTS(pktRx_); 			break;@@ -1159,17 +1493,35 @@ 		case MAC_Subtype_ACK: 			recvACK(pktRx_); 			break;+			// wqos - Fri 13 Oct 00, 15:48 - dugdale+		case MAC_Subtype_CFEnd:+			cfp_=0; // No longer a CFP if we receive a CFEnd frame+			//      set_nav(0);+			nav_=0;+			fprintf(stderr,"CFEnd received!\n");+			if(mhNav_.busy())+				mhNav_.stop();+			mac_log(pktRx_);+			pktRx_=0;+			tx_resume();+			break;+			// wqos - changes by dugdale ends 		default: 			fprintf(stderr,"recvTimer1:Invalid MAC Control Subtype %x\n", 				subtype); 			exit(1);-		}+			} 		break; 	case MAC_Type_Data: 		switch(subtype) { 		case MAC_Subtype_Data: 			recvDATA(pktRx_); 			break;+		// wqos - Mon 09 Oct 00, 17:37 - dugdale +		case MAC_Subtype_CFPoll:+			recvPoll(pktRx_);+			break;+		// wqos - changes by dugdale ends			 		default: 			fprintf(stderr, "recv_timer2:Invalid MAC Data Subtype %x\n", 				subtype);@@ -1191,7 +1543,10 @@ { 	struct rts_frame *rf = (struct rts_frame*)p->access(hdr_mac::offset_); -	if(tx_state_ != MAC_IDLE) {+// wqos - Mon 20 Nov 00, 19:30 - dugdale +	// We shouldn't answer an RTS during a CFP+	if(tx_state_ != MAC_IDLE||cfp_) {+// wqos - changes by dugdale ends 		discard(p, DROP_MAC_BUSY); 		return; 	}@@ -1284,6 +1639,18 @@ 				ssrc_ = 0; 				rst_cw(); 			}+			 // wqos - Tue 07 Nov 00, 15:38 - dugdale +			// If we were polling, we could receive data even without+			// having sent a CTS+			else if(tx_state_ == MAC_POLLING) {+				assert(pktPCF_);+				Packet::free(pktPCF_); pktPCF_ = 0;+				if(mhSend_.busy())+					mhSend_.stop();+				ssrc_ = 0;+				rst_cw();+			}+			// wqos - changes by dugdale ends 			else { 				discard(p, DROP_MAC_BUSY); 				//printf("(%d)..discard DATA\n",index_);@@ -1381,3 +1748,456 @@  	mac_log(p); }+++// wqos - Wed 29 Nov 00, 13:20 - dugdale+void+Mac802_11::recvPoll(Packet *p) {+	Packet *tp;+	//      tp = ll_->ifq()->deque();+	//      tp = ((Queue *)((LL *)uptarget_)->downtarget())->deque();+	mac_log(p);+	//  rx_resume();+	// Hmmm... maybe not so good...+	//	if(mhBackoff_.busy() && !mhBackoff_.paused())+	if(mhBackoff_.busy())+		mhBackoff_.stop();+	//		mhBackoff_.pause();+ retryPoll:+	if(!pktTx_) {+  		// Unless there already is a packet to be sent, try to dequeuec one+		tp = ((Queue *)(ll_->downtarget()))->deque();+		if(tp) { // Did we get a packet from the queue?+			//	abort();+			//send(tp, 0);+			//if(!pollsToSend_)+			//pollsToSend_=1;+			trace_pkt(tp);++++			// Try with this commented out!!!+			// It is NOT good that the stuff below is here, but for some strange+			// reason it won't work without it... Not really correct, but it+			// works until I find out what's wrong.+			if(HDR_CMN(tp)->ptype()==PT_ARP||HDR_CMN(tp)->ptype()==PT_MESSAGE) {+				Packet::free(tp); tp=0;+				goto retryPoll;+			}+			sendDATA(tp);+			+			fprintf(stderr, "Hej %x %x %d %d!\n", ((struct hdr_mac802_11 *)pktTx_)->dh_fc.fc_type,((struct hdr_mac802_11 *)pktTx_)->dh_fc.fc_subtype,((struct hdr_mac802_11 *)HDR_MAC802_11(pktTx_))->dh_scontrol, pktTx_==0);+			+			+			((struct hdr_mac802_11 *)HDR_MAC802_11(pktTx_))->dh_scontrol = sta_seqno_++;+			((struct hdr_mac802_11 *)HDR_MAC802_11(pktTx_))->dh_duration = 32768;+		}+	} else {+		trace_pkt(pktTx_);+++		if(HDR_CMN(pktTx_)->ptype()==PT_ARP||HDR_CMN(pktTx_)->ptype()==PT_MESSAGE) {+			Packet::free(pktTx_); pktTx_=0;+			goto retryPoll;+		}+		+		//if(!pollsToSend_)+		//pollsToSend_=1;+		fprintf(stderr,"tx_state_:%x %d\n",tx_state_,cfp_);+		((struct hdr_mac802_11 *)HDR_MAC802_11(pktTx_))->dh_duration = 32768;+		+		if(pktRTS_) {+			// We won't be needing this RTS frame+			Packet::free(pktRTS_); pktRTS_=0; +		}+		+	}+	if(!mhDefer_.busy()&&pktTx_)+		mhDefer_.start(sifs_);+	++	// If there is no packet to send in the queue, the station won't do anything, so a+	// timer will time out at the PC, and a new poll frame will be sent (to another station)+	// Would be better if this station sent a "No data" frame in this case.+	// Not implemented yet.++}+// wqos - changes by dugdale ends+++// wqos - Mon 09 Oct 00, 20:01 - dugdale +void+Mac802_11::do_cfp()+{+	// Hmmm... Not much use having this function+	sendPoll();+}++void+Mac802_11::send_beacon()+{+	if(tx_state_!=MAC_SEND&&tx_state_!=MAC_CTS && rx_state_==MAC_IDLE) {+		// We can send the beacon now+		pcfSend(MAC_Type_Management, MAC_Subtype_Beacon);+	} else {+		// We have to wait to send the beacon, but set the flag+		// (btbs=beacon to be sent) so we know that it should be sent.+		btbs_=1;+	}+}++void+Mac802_11::sendPoll()+{+	pcfSend(MAC_Type_Data, MAC_Subtype_CFPoll);+}++void+Mac802_11::sendCFEnd()+{+	pcfSend(MAC_Type_Control, MAC_Subtype_CFEnd);+}+// wqos - changes by dugdale ends+++// wqos - Tue 24 Oct 00, 10:20 - dugdale+/*+	Function to send the control frames of the PCF mode.+	The frame sent depends on the arguments to the function.+	Called by send_beacon(), sendPoll(), and sendCFEnd().+ */+void+Mac802_11::pcfSend(int type, int subtype)+{+	Packet* p = Packet::alloc();+	struct hdr_mac802_11 *mh =  (struct hdr_mac802_11 *)p->access(hdr_mac::offset_);+	hdr_cmn* ch = HDR_CMN(p);+	ch->ptype()=PT_MAC;+	int dst = MAC_BROADCAST;+	double defertime=pifs_;+	Scheduler &s = Scheduler::instance();+    +	bzero(&mh->dh_fc, sizeof(struct frame_control));+	// Set some info in the frame+	mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;+	mh->dh_fc.fc_type       = type;+	mh->dh_fc.fc_subtype    = subtype;+	/*+	 * Assign the data packet a sequence number.+	 */+	mh->dh_scontrol = sta_seqno_++;+	ch->size() += ETHER_HDR_LEN;+  +	switch(type) {+	case MAC_Type_Management:+		switch(subtype) {+		case MAC_Subtype_Beacon:+			struct beacon_frame *beacon = (struct beacon_frame *)p->access(hdr_mac::offset_);+			// Schedule the transmission of the next beacon+			// Moved to beaconHandler()+			//			mhBeacon_.start(macmib_->dot11BeaconPeriod*0.001024);+      +			// do some timestamp stuff, and set it in the frame+			beacon->bf_timestamp=(unsigned long long)((Scheduler::instance()).clock()*1000);+      +			// Set the beacon interval in the frame+			beacon->bf_binterval=macmib_->dot11BeaconPeriod;+      +      +			//     assert(pktPCF_ == 0);++			fprintf(stderr, "Beacon sent at %f\n", Scheduler::instance().clock());+      +			// set the TIM stuff+			beacon->bf_tim.elemID       = MMFF_TIM;+			beacon->bf_tim.length       = 6;+			beacon->bf_tim.DTIMcount    = dtimcount_;+			beacon->bf_tim.DTIMperiod   = macmib_->dot11DTIMPeriod;+      +			beacon->bf_cfparamset.CFPCount  = cfpcount_;+			beacon->bf_cfparamset.CFPPeriod = macmib_->dot11CFPPeriod;+			beacon->bf_cfparamset.CFPMaxDuration = macmib_->dot11CFPMaxDuration;+      +			beacon->bf_duration = 0;+			if(dtimcount_==0) {+				// We have a DTIM, and might want to start a CFP+				dtimcount_=macmib_->dot11DTIMPeriod;+				cfpcount_--;+				beacon->bf_cfparamset.CFPCount  = cfpcount_;+				if(cfpcount_ == 0) { // Let's do a CFP+					//					cfp_ = 1; // CFP...+					cfpcount_ = macmib_->dot11CFPPeriod;+					// Calculate how many polls to send+					pollsToSend_=pollList_->numPollable()-1;+					// Calculate when the CFP must be over+					lastPoll_=s.clock()+tutos(macmib_->dot11CFPMaxDuration) - 2346/bandwidth_;+				}+			} else {+				dtimcount_--;+			}+			//     SET_TX_STATE(MAC_BEACONING); // HMMM...      +			break;+		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -