uint8_t RMAC_PutPayload(uint8_t *buf, size_t bufSize, uint8_t payloadSize, RPHY_FlagsType flags) { if (flags&RPHY_PACKET_FLAGS_REQ_ACK) { RMAC_BUF_TYPE(buf) = RMAC_MSG_TYPE_DATA|RMAC_MSG_TYPE_REQ_ACK; } else { RMAC_BUF_TYPE(buf) = RMAC_MSG_TYPE_DATA; } RMAC_ExpectedAckSeqNr = RMAC_SeqNr; RMAC_BUF_SEQN(buf) = RMAC_SeqNr++; return RPHY_PutPayload(buf, bufSize, payloadSize+RMAC_HEADER_SIZE, flags); }
void RMAC_DecodeType(uint8_t *buf, size_t bufSize, RPHY_PacketDesc *packet) { RMAC_MsgType type; bool first = TRUE; type = RMAC_BUF_TYPE(packet->phyData); buf[0] = '\0'; UTIL1_chcat(buf, bufSize, '('); if (type&RMAC_MSG_TYPE_REQ_ACK) { UTIL1_strcat(buf, bufSize, (unsigned char*)"RACK"); first = FALSE; } if (type&RMAC_MSG_TYPE_DATA) { if (!first) { UTIL1_chcat(buf, bufSize, '|'); } UTIL1_strcat(buf, bufSize, (unsigned char*)"DATA"); first = FALSE; } if (type&RMAC_MSG_TYPE_ACK) { if (!first) { UTIL1_chcat(buf, bufSize, '|'); } UTIL1_strcat(buf, bufSize, (unsigned char*)"ACK"); first = FALSE; } if (type&RMAC_MSG_TYPE_CMD) { UTIL1_strcat(buf, bufSize, (unsigned char*)"CMD"); first = FALSE; } UTIL1_chcat(buf, bufSize, ')'); }
void RAPP_SniffPacket(RPHY_PacketDesc *packet, bool isTx) { uint8_t buf[32]; const CLS1_StdIOType *io; int i; uint8_t dataSize; RNWK_ShortAddrType addr; io = CLS1_GetStdio(); if (isTx) { CLS1_SendStr((unsigned char*)"Packet Tx ", io->stdOut); } else { CLS1_SendStr((unsigned char*)"Packet Rx ", io->stdOut); } UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"flags: "); UTIL1_strcatNum16s(buf, sizeof(buf), packet->flags); CLS1_SendStr(buf, io->stdOut); if (packet->flags!=RPHY_PACKET_FLAGS_NONE) { CLS1_SendStr((unsigned char*)"(", io->stdOut); if (packet->flags&RPHY_PACKET_FLAGS_IS_ACK) { CLS1_SendStr((unsigned char*)"IS_ACK,", io->stdOut); } if (packet->flags&RPHY_PACKET_FLAGS_REQ_ACK) { CLS1_SendStr((unsigned char*)"REQ_ACK", io->stdOut); } CLS1_SendStr((unsigned char*)")", io->stdOut); } UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" size: "); UTIL1_strcatNum16s(buf, sizeof(buf), packet->phySize); CLS1_SendStr(buf, io->stdOut); /* PHY */ CLS1_SendStr((unsigned char*)" PHY data: ", io->stdOut); dataSize = RPHY_BUF_SIZE(packet->phyData); for(i=0; i<dataSize+RPHY_HEADER_SIZE;i++) { buf[0] = '\0'; UTIL1_strcatNum8Hex(buf, sizeof(buf), packet->phyData[i]); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" "); CLS1_SendStr(buf, io->stdOut); } /* MAC */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" MAC size:"); UTIL1_strcatNum8u(buf, sizeof(buf), dataSize); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" type:"); UTIL1_strcatNum8Hex(buf, sizeof(buf), RMAC_BUF_TYPE(packet->phyData)); CLS1_SendStr(buf, io->stdOut); RMAC_DecodeType(buf, sizeof(buf), packet); CLS1_SendStr(buf, io->stdOut); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" s#:"); UTIL1_strcatNum8Hex(buf, sizeof(buf), RMAC_BUF_SEQN(packet->phyData)); CLS1_SendStr(buf, io->stdOut); /* NWK */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" NWK src:"); addr = RNWK_BUF_GET_SRC_ADDR(packet->phyData); #if RNWK_SHORT_ADDR_SIZE==1 UTIL1_strcatNum8Hex(buf, sizeof(buf), addr); #else UTIL1_strcatNum16Hex(buf, sizeof(buf), addr); #endif UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" dst:"); addr = RNWK_BUF_GET_DST_ADDR(packet->phyData); #if RNWK_SHORT_ADDR_SIZE==1 UTIL1_strcatNum8Hex(buf, sizeof(buf), addr); #else UTIL1_strcatNum16Hex(buf, sizeof(buf), addr); #endif CLS1_SendStr(buf, io->stdOut); /* APP */ if (dataSize>RMAC_HEADER_SIZE+RNWK_HEADER_SIZE) { /* there is application data */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" APP type:"); UTIL1_strcatNum8Hex(buf, sizeof(buf), RAPP_BUF_TYPE(packet->phyData)); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" size:"); UTIL1_strcatNum8Hex(buf, sizeof(buf), RAPP_BUF_SIZE(packet->phyData)); CLS1_SendStr(buf, io->stdOut); } CLS1_SendStr((unsigned char*)"\r\n", io->stdOut); }
RMAC_MsgType RMAC_GetType(uint8_t *buf, size_t bufSize) { (void)bufSize; /* not used */ return RMAC_BUF_TYPE(buf); }
uint8_t RMAC_SendACK(RPHY_PacketDesc *packet) { /* send an ack message back: this is is of type ack with src and dst address */ RMAC_BUF_TYPE(packet->data) = RMAC_MSG_TYPE_ACK; /* set type to ack */ /* use same sequence number as in the received package, so no change */ return RPHY_PutPayload(packet->data, packet->dataSize, RMAC_HEADER_SIZE+RNWK_HEADER_SIZE); }
uint8_t RMAC_PutPayload(uint8_t *buf, size_t bufSize, uint8_t payloadSize) { RMAC_BUF_TYPE(buf) = RMAC_MSG_TYPE_DATA; RMAC_ExpectedAckSeqNr = RMAC_SeqNr; RMAC_BUF_SEQN(buf) = RMAC_SeqNr++; return RPHY_PutPayload(buf, bufSize, payloadSize+RMAC_HEADER_SIZE); }
uint8_t RMAC_SendACK(RPHY_PacketDesc *rxPacket, RPHY_PacketDesc *ackPacket) { RMAC_BUF_TYPE(ackPacket->phyData) = RMAC_MSG_TYPE_ACK; /* set type to ack */ RMAC_BUF_SEQN(ackPacket->phyData) = RMAC_BUF_SEQN(rxPacket->phyData); /* use same sequence number as in the received package, so no change */ return RPHY_PutPayload(ackPacket->phyData, ackPacket->phySize, RMAC_HEADER_SIZE+RNWK_HEADER_SIZE, RPHY_PACKET_FLAGS_NONE); }