📄 mac01.c
字号:
msdu_length = pdu->length - data_len;
/*
for(i=0 ; i < msdu_length; i++)
{
payload[i] = pdu->data[data_len +i];
}
*/
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;
/*
for(i=0 ; i < msdu_length; i++)
{
payload[i] = pdu->data[data_len +i];
}
*/
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)
{
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)
{
//////////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];
////////////printfUART("PC CMD SN: %i TYPE %x\n", pdu->seq_num,cmd_type);
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磎 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;
//SrcAddr[0]=0x00000002;
//SrcAddr[1]=0x00000002;
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", "");
//atomic{
//////printfUART("DR\n", "");
if ( get_fc1_ack_request(pdu->frame_control1) == 1 )
{
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);
//}
//send_ind_trans_addr(LONG_ADDRESS, &cmd_data_request_0_3_reception->source_address0);
break;
case CMD_PANID_CONFLICT:
break;
case CMD_ORPHAN_NOTIFICATION:
break;
case CMD_BEACON_REQUEST:
break;
case CMD_COORDINATOR_REALIGNMENT:
break;
case CMD_GTS_REQUEST:
////////////printfUART("Received CMD_GTS_REQUEST\n", "");
if ( get_fc1_ack_request(pdu->frame_control1) == 1 )
{
build_ack(pdu->seq_num,0);
}
process_gts_request(pdu);
break;
default: break;
}
return;
}
void indication_ack(MPDU *pdu, int8_t ppduLinkQuality)
{
//decrement buffer count
atomic buffer_count --;
////////////printfUART("ACK Received\n","");
atomic{
if (send_ack_check == 1 && ack_sequence_number_check == pdu->seq_num)
{
//transmission SUCCESS
call T_ackwait.stop();
send_buffer_count --;
send_buffer_msg_out++;
//failsafe
if(send_buffer_count > SEND_BUFFER_SIZE)
{
send_buffer_count =0;
send_buffer_msg_out=0;
send_buffer_msg_in=0;
}
if (send_buffer_msg_out == SEND_BUFFER_SIZE)
send_buffer_msg_out=0;
//received an ack for the association request
if( associating == 1 && association_cmd_seq_num == pdu->seq_num )
{
//////////printfUART("ASSOC ACK\n","");
call T_ResponseWaitTime.start(TIMER_ONE_SHOT, response_wait_time);
}
if (gts_request == 1 && gts_request_seq_num == pdu->seq_num)
{
call T_ResponseWaitTime.start(TIMER_ONE_SHOT, response_wait_time);
}
//////////printfUART("TRANSMISSION SUCCESS\n","");
if (send_indirect_transmission > 0 )
{ //the message send was indirect
//remove the message from the indirect transmission queue
indirect_trans_queue[send_indirect_transmission-1].handler=0x00;
indirect_trans_count--;
//////////printfUART("SU id:%i ct:%i\n", send_indirect_transmission,indirect_trans_count);
}
send_ack_check=0;
retransmit_count=0;
ack_sequence_number_check=0;
if (send_buffer_count > 0)
post send_frame_csma();
}
}
//CHECK
if (get_fc1_frame_pending(pdu->frame_control1) == 1 && pending_request_data ==1)// && associating == 1
{
//////////printfUART("Frame_pending\n","");
pending_request_data=0;
create_data_request_cmd();
}
//GTS mechanism, after the confirmation of the GTS request, must check if the beacon has the gts
/*
if (gts_ack == 1)
{
gts_ack=0;
gts_confirm=1;
call T_ResponseWaitTime.stop();
}
*/
if(gts_send_pending_data==1)
post start_gts_send();
if(coordinator_gts_send_pending_data==1 && coordinator_gts_send_time_slot == number_time_slot)
post start_coordinator_gts_send();
return;
}
/*****************************************************
****************PLME_ED EVENTS***********************
******************************************************/
event result_t PLME_CCA.confirm(uint8_t status){
return SUCCESS;
}
event result_t PLME_SET.confirm(uint8_t status, uint8_t PIBAttribute){
return SUCCESS;
}
async event result_t PLME_SET_TRX_STATE.confirm(uint8_t status){
/*
if(pending_reset)
{
atomic{
if(status==SUCCESS)
{
init_MacCon();
if(SetDefaultPIB) init_MacPIB();
signal MLME_RESET.confirm(MAC_SUCCESS);
}
else
{
signal MLME_RESET.confirm(MAC_DISABLE_TRX_FAILURE);
}
pending_reset=0;
}
}
*/
return SUCCESS;
}
event result_t PLME_GET.confirm(uint8_t status,uint8_t PIBAttribute, uint8_t PIBAttributeValue){
return SUCCESS;
}
event result_t PLME_ED.confirm(uint8_t status,int8_t EnergyLevel){
/*
if ( scanning_channels == 1)
{
if ( scanned_values[scan_count] > EnergyLevel )
scanned_values[scan_count] = EnergyLevel;
}
*/
return SUCCESS;
}
/*****************************************************/
/* TIMERS FIRED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -