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

📄 macp.nc

📁 tinyos-2.x.rar
💻 NC
📖 第 1 页 / 共 5 页
字号:
					//////////printfUART("data rejected, wrong destination PAN\n", ""); 
					return;
				}
				data_len = 20;
				
				
				DstAddr[1] = dest_long_ptr->destination_address0;
				DstAddr[0] =dest_long_ptr->destination_address1;
				
				SrcAddr[1] =source_long_ptr->source_address0;
				SrcAddr[0] =source_long_ptr->source_address1;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				signal MCPS_DATA.indication((uint16_t)source_address, (uint16_t)source_long_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_long_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  
				
			}
			
			// Destination SHORT - Source LONG
			if ( destination_address == SHORT_ADDRESS && source_address == LONG_ADDRESS )
			{
				dest_short_ptr = (dest_short *) &pdu->data[0];
				source_long_ptr = (source_long *) &pdu->data[DEST_SHORT_LEN];
				
				//If a short destination address is included in the frame, it shall match either macShortAddress or the
				//broadcast address (0 x ffff). Otherwise, if an extended destination address is included in the frame, it
				//shall match aExtendedAddress.
				if ( dest_short_ptr->destination_address != 0xffff && dest_short_ptr->destination_address != mac_PIB.macShortAddress)
				{
					//////////printfUART("data rejected, short destination not for me\n", ""); 
					return;
				}
				//If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the
				//broadcast PAN identifier (0 x ffff).
				if(dest_short_ptr->destination_PAN_identifier != 0xffff && dest_short_ptr->destination_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, wrong destination PAN\n", ""); 
					return;
				}
				
				data_len = 14;
				
				DstAddr[0] =dest_short_ptr->destination_address;
				
				SrcAddr[1] =source_long_ptr->source_address0;
				SrcAddr[0] =source_long_ptr->source_address1;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				signal MCPS_DATA.indication((uint16_t)source_address, (uint16_t)source_long_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_short_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
			// Destination LONG - Source SHORT
			if ( destination_address == LONG_ADDRESS && source_address == SHORT_ADDRESS )
			{
				dest_long_ptr = (dest_long *) &pdu->data[0];
				source_short_ptr = (source_short *) &pdu->data[DEST_LONG_LEN];
				
				//If a short destination address is included in the frame, it shall match either macShortAddress or the
				//broadcast address (0 x ffff). Otherwise, if an extended destination address is included in the frame, it
				//shall match aExtendedAddress.
				if ( dest_long_ptr->destination_address0 !=aExtendedAddress0 && dest_long_ptr->destination_address1 !=aExtendedAddress1 )
				{
					//////////printfUART("data rejected, ext destination not for me\n", ""); 
					return;
				}
				//If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the
				//broadcast PAN identifier (0 x ffff).
				if(dest_long_ptr->destination_PAN_identifier != 0xffff && dest_long_ptr->destination_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, wrong destination PAN\n", ""); 
					return;
				}
				
				data_len = 14;
				
				DstAddr[1] = dest_long_ptr->destination_address0;
				DstAddr[0] =dest_long_ptr->destination_address1;
				
				
				SrcAddr[0] =source_short_ptr->source_address;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				signal MCPS_DATA.indication((uint16_t)source_address, (uint16_t)source_short_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_long_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
			
			
			//Destination SHORT - Source SHORT
			if ( destination_address == SHORT_ADDRESS && source_address == SHORT_ADDRESS )	
			{
				dest_short_ptr = (dest_short *) &pdu->data[0];
				source_short_ptr = (source_short *) &pdu->data[DEST_SHORT_LEN];
				
				//If a short destination address is included in the frame, it shall match either macShortAddress or the
				//broadcast address (0 x ffff). Otherwise, if an extended destination address is included in the frame, it
				//shall match aExtendedAddress.
				if ( dest_short_ptr->destination_address != 0xffff && dest_short_ptr->destination_address != mac_PIB.macShortAddress)
				{
					//printfUART("data rejected, short destination not for me\n", ""); 
					return;
				}
				//If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the
				//broadcast PAN identifier (0 x ffff).
				if(dest_short_ptr->destination_PAN_identifier != 0xffff && dest_short_ptr->destination_PAN_identifier != mac_PIB.macPANId )
				{
					//printfUART("SH SH data rejected, wrong destination PAN %x\n",mac_PIB.macPANId ); 
					return;
				}
				
				data_len = 8;
				
				if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
				{
					build_ack(pdu->seq_num,0);
				}
				
				DstAddr[0] =dest_short_ptr->destination_address;
				
				SrcAddr[0] =source_short_ptr->source_address;
				
				msdu_length = (pdu->length - 5) - data_len;
				
				
				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
			
				signal MCPS_DATA.indication((uint16_t)source_address, (uint16_t)source_short_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_short_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length,payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
		}
		
		/*********NO DESTINATION ADDRESS PRESENT ****************/
		
		if ( destination_address == 0 && source_address > 1 )
		{
				
			if (source_address == LONG_ADDRESS)
			{//Source LONG
				source_long_ptr = (source_long *) &pdu->data[0];
				
				//If only source addressing fields are included in a data or MAC command frame, the frame shall be
				//accepted only if the device is a PAN coordinator and the source PAN identifier matches macPANId.
				if ( PANCoordinator==0 || source_long_ptr->source_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, im not pan\n", ""); 
					return;
				}
				
				data_len = 10;
				
				SrcAddr[1] =source_long_ptr->source_address0;
				SrcAddr[0] =source_long_ptr->source_address1;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				signal MCPS_DATA.indication((uint16_t)source_address,(uint16_t)source_long_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, 0x0000, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
			else
			{//Source SHORT

				source_short_ptr = (source_short *) &pdu->data[0];
				//If only source addressing fields are included in a data or MAC command frame, the frame shall be
				//accepted only if the device is a PAN coordinator and the source PAN identifier matches macPANId.
				if ( PANCoordinator==0 || source_short_ptr->source_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, im not pan\n", ""); 
					return;
				}
				
				data_len = 4;

				
				SrcAddr[0] =source_short_ptr->source_address;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				signal MCPS_DATA.indication((uint16_t)source_address, (uint16_t)source_short_ptr->source_PAN_identifier, SrcAddr,(uint16_t)destination_address, 0x0000, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
		}
		/*********NO SOURCE ADDRESS PRESENT ****************/
		
		if ( destination_address > 1 && source_address == 0 )
		{
			if (destination_address == LONG_ADDRESS)
			{//Destination LONG
				dest_long_ptr = (dest_long *) &pdu->data[0];
				
				//If a short destination address is included in the frame, it shall match either macShortAddress or the
				//broadcast address (0 x ffff). Otherwise, if an extended destination address is included in the frame, it
				//shall match aExtendedAddress.
				if ( dest_long_ptr->destination_address0 !=aExtendedAddress0 && dest_long_ptr->destination_address1 !=aExtendedAddress1 )
				{
					//////////printfUART("data rejected, ext destination not for me\n", ""); 
					return;
				}
				//If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the
				//broadcast PAN identifier (0 x ffff).
				if(dest_long_ptr->destination_PAN_identifier != 0xffff && dest_long_ptr->destination_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, wrong destination PAN\n", ""); 
					return;
				}
				
				data_len = 10;
				
				DstAddr[1] = dest_long_ptr->destination_address0;
				DstAddr[0] =dest_long_ptr->destination_address1;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
			
				signal MCPS_DATA.indication((uint16_t)source_address,0x0000, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_long_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

			}
			else
			{//Destination SHORT
				dest_short_ptr = (dest_short *) &pdu->data[0];
				
				//If a short destination address is included in the frame, it shall match either macShortAddress or the
				//broadcast address (0 x ffff). Otherwise, if an extended destination address is included in the frame, it
				//shall match aExtendedAddress.
				if ( dest_short_ptr->destination_address != 0xffff && dest_short_ptr->destination_address != mac_PIB.macShortAddress)
				{
					//////////printfUART("data rejected, short destination not for me\n", ""); 
					return;
				}
				//If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the
				//broadcast PAN identifier (0 x ffff).
				if(dest_short_ptr->destination_PAN_identifier != 0xffff && dest_short_ptr->destination_PAN_identifier != mac_PIB.macPANId )
				{
					//////////printfUART("data rejected, wrong destination PAN\n", ""); 
					return;
				}
				
				data_len = 4;
				
				DstAddr[0] =dest_short_ptr->destination_address;
				
				msdu_length = pdu->length - data_len;

				memcpy(&payload,&pdu->data[data_len],msdu_length * sizeof(uint8_t));
				
				
				signal MCPS_DATA.indication((uint16_t)source_address,0x0000, SrcAddr,(uint16_t)destination_address, (uint16_t)dest_short_ptr->destination_PAN_identifier, DstAddr, (uint16_t)msdu_length, payload, (uint16_t)ppduLinkQuality, 0x0000,0x0000);  

				data_len = 4;
			}
		}
		
	}
	else
	{
	//intra_pan == 1
	
	
	
	}
	
	
return;
}

void indication_cmd(MPDU *pdu, int8_t ppduLinkQuality)
{
		uint8_t cmd_type;
		//uint8_t pk_ptr;
		uint8_t addressing_fields_length=0;
		
		uint32_t SrcAddr[2];
		//uint32_t DstAddr[2];//NOT USED SO FAR
		
		//frame control variables
		uint8_t source_address=0;
		uint8_t destination_address=0;
	
		//NOT USED SO FAR
		//dest_short *dest_short_ptr;
		//dest_long *dest_long_ptr;
		//NOT USED SO FAR
		//source_short *source_short_ptr;
		source_long *source_long_ptr;
		
		dest_short *dest_short_ptr;
		dest_long *dest_long_ptr;
		
		//CHECK IMPLEMENT
		//intra_pan_source_short *intra_pan_source_short_ptr; 
		//intra_pan_source_long *intra_pan_source_long_ptr;
		
		destination_address=get_fc2_dest_addr(pdu->frame_control2);
		source_address=get_fc2_source_addr(pdu->frame_control2);
		
		//decrement buffer count
		atomic buffer_count --;
		
		switch(destination_address)
		{
			case LONG_ADDRESS: addressing_fields_length = DEST_LONG_LEN;
								dest_long_ptr = (dest_long *) &pdu->data[0];
								if(dest_long_ptr->destination_address0 !=aExtendedAddress0 && dest_long_ptr->destination_address1 !=aExtendedAddress1)
								{
									printfUART("NOT FOR ME","");
									return;
								}
								
								break;
			case SHORT_ADDRESS: addressing_fields_length = DEST_SHORT_LEN;
								dest_short_ptr= (dest_short *) &pdu->data[0];
								//destination command not for me
								if (dest_short_ptr->destination_address != mac_PIB.macShortAddress && dest_short_ptr->destination_address !=0xffff)
								{
									printfUART("NOT FOR ME","");
									//////////printfUART("NOT FOR ME %x me %e\n", dest_short_ptr->destination_address,mac_PIB.macShortAddress); 
									return;
								}
								break;
		}
		switch(source_address)
		{
			case LONG_ADDRESS: addressing_fields_length = addressing_fields_length + SOURCE_LONG_LEN;
								break;
			case SHORT_ADDRESS: addressing_fields_length = addressing_fields_length + SOURCE_SHORT_LEN;
								break;
		}

		cmd_type = pdu->data[addressing_fields_length];
		
				
		switch(cmd_type)
		{
		
		case CMD_ASSOCIATION_REQUEST: 	
									//check if association is allowed, if not discard the frame		
									
									//////printfUART("CMD_ASSOCIATION_REQUEST \n", "");
									
										
											if (mac_PIB.macAssociationPermit == 0 )
											{
												//////////printfUART("Association not alowed\n", "");
												if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
												{
													build_ack(pdu->seq_num,0);
												}
												return;
											}
											
											if ( PANCoordinator==0 )
											{
												//////////printfUART("i�m not a pan\n", ""); 
												return;
											}
									atomic{
											source_long_ptr = (source_long *) &pdu->data[DEST_SHORT_LEN];
											
											SrcAddr[1] =source_long_ptr->source_address0;
											SrcAddr[0] =source_long_ptr->source_address1;
											
											
											signal MLME_ASSOCIATE.indication(SrcAddr, pdu->data[addressing_fields_length+1] , 0, 0);

											}
											
											if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
											{
												build_ack(pdu->seq_num,1);
											}	

											
									break;
		
		case CMD_ASSOCIATION_RESPONSE: atomic{
												printfUART("CMD_ASSOCIATION_RESPONSE\n", ""); 
												
												associating =0;
												call T_ResponseWaitTime.stop();
												
												if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
												{
													build_ack(pdu->seq_num,0);
												}
											
												signal MLME_ASSOCIATE.confirm((uint16_t)(pdu->data[addressing_fields_length+1] + (pdu->data[addressing_fields_length+2] << 8)), pdu->data[addressing_fields_length+3]);
												}
										break;

		case CMD_DISASSOCIATION_NOTIFICATION: 	//////////printfUART("Received CMD_DISASSOCIATION_NOTIFICATION\n", ""); 
												
												if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
												{
													build_ack(pdu->seq_num,0);
												}
												
												process_dissassociation_notification(pdu);
												break;
		case CMD_DATA_REQUEST: 
								//printfUART("CMD_DATA_REQUEST\n", ""); 
									//////printfUART("DR\n", "");
									if ( get_fc1_ack_request(pdu->frame_control1) == 1 ) 
									{
										//TODO
										//Problems with consecutive reception of messages
										
										build_ack(pdu->seq_num,0);
									}
									
									//cmd_data_request_0_3_reception = (cmd_data_request_0_3 *) pdu->data;
									
									source_long_ptr = (source_long *) &pdu->data[0];
											
									SrcAddr[1] =source_long_ptr->source_address0;
									SrcAddr[0] =source_long_ptr->source_address1;
									
									send_ind_trans_addr(SrcAddr);

								break;
		case CMD_PANID_CONFLICT:
								break;
								
		case CMD_ORPHAN_NOTIFICATION:
									//printfUART("CMD_ORPHAN_NOTIFICATION\n", ""); 
									
									source_long_ptr = (source_long *) &pdu->data[DEST_SHORT_LEN];
											
									SrcAddr[1] =source_long_ptr->source_address0;
									SrcAddr[0] =source_long_ptr->source_address1;
									
									signal MLME_ORPHAN.indication(SrcAddr, 0x00,0x00);
								
		
								break;
		case CMD_BEACON_REQUEST:
								break;
		case CMD_COORDINATOR_REALIGNMENT:
									printfUART("CMD_COORDINATOR_REALIGNMENT\n", ""); 
									
									process_coordinator_realignment(pdu);
									
								break;
		case CMD_GTS_REQUEST: 	
								////////////printfUART("Received CMD_GTS_REQUEST\n", ""); 
								if ( get_fc1_ack_request(

⌨️ 快捷键说明

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