📄 macp.nc
字号:
for(i=0; i< gts_des_count; i++)
{
gts_descriptor_addr = (uint16_t) packet->data[data_count];
////printfUART("gts_des_addr:%x mac short:%x\n",gts_descriptor_addr,mac_PIB.macShortAddress);
data_count = data_count+2;
//check if it concerns me
if (gts_descriptor_addr == mac_PIB.macShortAddress)
{
//confirm the gts request
//////////////printfUART("packet->data[data_count]: %x\n",packet->data[data_count]);
//gts_ss = 15 - get_gts_descriptor_ss(packet->data[data_count]);
gts_ss = get_gts_descriptor_ss(packet->data[data_count]);
gts_l = get_gts_descriptor_len(packet->data[data_count]);
if ( i == 0 )
{
dir_mask=1;
}
else
{
dir_mask = powf(2,i);
}
//////////////printfUART("dir_mask: %x i: %x gts_directions: %x \n",dir_mask,i,gts_directions);
dir = ( gts_directions & dir_mask);
if (dir == 0)
{
s_GTSss=gts_ss;
s_GTS_length=gts_l;
}
else
{
r_GTSss=gts_ss;
r_GTS_length=gts_l;
}
////printfUART("PB gts_ss: %i gts_l: %i dir: %i \n",gts_ss,gts_l,dir);
//////////////printfUART("PB send_s_GTSss: %i send_s_GTS_len: %i\n",send_s_GTSss,send_s_GTS_len);
if ( gts_l == 0 )
{
allow_gts=0;
}
if (gts_confirm == 1 && gts_l != 0)
{
//signal ok
////printfUART("gts confirm \n","");
gts_confirm =0;
signal MLME_GTS.confirm(GTS_specification,MAC_SUCCESS);
}
else
{
//signal not ok
//////////////printfUART("gts not confirm \n","");
gts_confirm =0;
signal MLME_GTS.confirm(GTS_specification,MAC_DENIED);
}
}
data_count++;
}
}
/**********************************************************************************/
/* PROCESS PENDING ADDRESSES INFORMATION */
/**********************************************************************************/
//this should pass to the network layer
short_addr_pending=get_number_short(packet->data[data_count]);
long_addr_pending=get_number_extended(packet->data[data_count]);
////////////printfUART("ADD COUNT %i %i\n",short_addr_pending,long_addr_pending);
data_count++;
if(short_addr_pending > 0)
{
for(i=0;i < short_addr_pending;i++)
{
////////////printfUART("PB %i %i\n",(uint16_t)packet->data[data_count],short_addr_pending);
//if(packet->data[data_count] == (uint8_t)mac_PIB.macShortAddress && packet->data[data_count+1] == (uint8_t)(mac_PIB.macShortAddress >> 8) )
if((uint16_t)packet->data[data_count] == mac_PIB.macShortAddress)
{
create_data_request_cmd();
}
data_count = data_count + 2;
}
}
if(long_addr_pending > 0)
{
for(i=0; i < long_addr_pending;i++)
{
if((uint32_t)packet->data[data_count] == aExtendedAddress0 && (uint32_t)packet->data[data_count + 4] == aExtendedAddress1)
{
data_count = data_count + 8;
}
}
}
/**********************************************************************************/
/* BUILD the PAN descriptor of the COORDINATOR */
/**********************************************************************************/
//Beacon NOTIFICATION
//BUILD the PAN descriptor of the COORDINATOR
//assuming that the adress is short
pan_descriptor.CoordAddrMode = SHORT_ADDRESS;
pan_descriptor.CoordPANId = 0x0000;//beacon_ptr->source_PAN_identifier;
pan_descriptor.CoordAddress0=0x00000000;
pan_descriptor.CoordAddress1=mac_PIB.macCoordShortAddress;
pan_descriptor.LogicalChannel=current_channel;
//superframe specification field
pan_descriptor.SuperframeSpec = beacon_ptr->superframe_specification;
pan_descriptor.GTSPermit=mac_PIB.macGTSPermit;
pan_descriptor.LinkQuality=0x00;
pan_descriptor.TimeStamp=0x000000;
pan_descriptor.SecurityUse=0;
pan_descriptor.ACLEntry=0x00;
pan_descriptor.SecurityFailure=0x00;
//I_AM_IN_CAP = 1;
/**********************************************************************************/
/* SYNCHRONIZING */
/**********************************************************************************/
//processing time + beacon transmission delay
//removed not used
//process_tick_counter = call TimerAsync.get_process_frame_tick_counter();
//removed not used
//start_reset_ct = ((1000 * (packet->length * 8.0) / 250)) / 69.54; //(process_tick_counter - receive_tick_counter);
if(PANCoordinator == 0)
{
I_AM_IN_CAP = 1;
I_AM_IN_IP = 0;
//call Leds.yellowOn();
call Leds.led2On();
call Leds.led1On();
if(findabeacon == 1)
{
////printfUART("findabeacon\n", "");
call TimerAsync.set_timers_enable(1);
findabeacon =0;
}
//#ifdef PLATFORM_MICAZ
//number_time_slot = call TimerAsync.reset_start(start_reset_ct+process_tick_counter+52);// //SOBI=3 52 //SOBI=0 15
//#else
//call TimerAsync.reset();
number_time_slot = call TimerAsync.reset_start(75); //95 old val sem print
// +process_tick_counter+52 //SOBI=3 52 //SOBI=0
//#endif
on_sync=1;
////printfUART("sED\n", "");
}
signal MLME_BEACON_NOTIFY.indication((uint8_t)packet->seq_num,pan_descriptor,0, 0, mac_PIB.macBeaconPayloadLenght, packet->data);
return;
}
void process_gts_request(MPDU *pdu)
{
error_t status;
cmd_gts_request *mac_gts_request;
mac_gts_request= (cmd_gts_request*) &pdu->data;
atomic{
if ( get_characteristic_type(mac_gts_request->gts_characteristics) == 1)
{
//allocation
//process the gts request
status = add_gts_entry(get_gts_length(mac_gts_request->gts_characteristics),get_gts_direction(mac_gts_request->gts_characteristics),mac_gts_request->source_address);
}
else
{
//dealocation
status = remove_gts_entry(mac_gts_request->source_address);
}
signal MLME_GTS.indication(mac_gts_request->source_address, mac_gts_request->gts_characteristics, 0, 0);
}
return;
}
/****************DATA indication functions******************/
void indication_data(MPDU *pdu, int8_t ppduLinkQuality)
{
uint8_t data_len;
uint8_t payload[80];
uint8_t msdu_length=0;
//int i;
uint32_t SrcAddr[2];
uint32_t DstAddr[2];
//frame control variables
uint8_t source_address=0;
uint8_t destination_address=0;
dest_short *dest_short_ptr;
dest_long *dest_long_ptr;
source_short *source_short_ptr;
source_long *source_long_ptr;
//implement the intra PAN data messages
//intra_pan_source_short *intra_pan_source_short_ptr;
//intra_pan_source_long *intra_pan_source_long_ptr;
source_address=get_fc2_source_addr(pdu->frame_control2);
destination_address=get_fc2_dest_addr(pdu->frame_control2);
//decrement buffer count
atomic buffer_count --;
SrcAddr[0]=0x00000000;
SrcAddr[1]=0x00000000;
DstAddr[0]=0x00000000;
DstAddr[1]=0x00000000;
////printfUART("id %i %i \n",source_address,destination_address);
if ( get_fc1_intra_pan(pdu->frame_control1)== 0 )
{
//INTRA PAN
if (destination_address > 1 && source_address > 1)
{
// Destination LONG - Source LONG
if (destination_address == LONG_ADDRESS && source_address == LONG_ADDRESS)
{
dest_long_ptr = (dest_long *) &pdu->data[0];
source_long_ptr = (source_long *) &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 = 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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -