Skip to content

Commit

Permalink
FW-867. Update packetfunctions API
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyClaeys committed Jun 25, 2020
1 parent 0d42c1f commit 479ecc6
Show file tree
Hide file tree
Showing 35 changed files with 1,578 additions and 1,052 deletions.
701 changes: 352 additions & 349 deletions bsp/boards/openmote-cc2538/radio.c

Large diffs are not rendered by default.

50 changes: 29 additions & 21 deletions inc/opendefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ enum {
ERR_6LORH_DEADLINE_DROPPED = 0x0d, // packet expiry time reached, dropped
ERR_UNEXPECTED_DAO = 0x0e, // unexpected DAO (code location {0}). A change maybe happened on dagroot node.
ERR_UNSUPPORTED_ICMPV6_TYPE = 0x0f, // unsupported ICMPv6 type {0} (code location {1})
ERR_6LOWPAN_UNSUPPORTED = 0x10, // unsupported 6LoWPAN parameter {1} at location {0}
ERR_6LOWPAN_UNSUPPORTED = 0x10, // unsupported 6LoWPAN parameter {1} at location {0}, dropping packet
ERR_NO_NEXTHOP = 0x11, // no next hop for layer 3 destination {0:x}{1:x}
ERR_INVALID_FWDMODE = 0x12, // invalid forward mode
ERR_LARGE_DAGRANK = 0x13, // large DAGrank {0}, set to {1}
Expand Down Expand Up @@ -264,22 +264,25 @@ enum {
ERR_GETDATA_ASKS_TOO_FEW_BYTES = 0x3f, // getData asks for too few bytes, maxNumBytes={0}, fill level={1}
ERR_WRONG_CRC_INPUT = 0x40, // wrong CRC in input Buffer
// cross layer
ERR_BUFFER_OVERFLOW = 0x41, // buffer overflow detected (code location {0})
ERR_BUSY_SENDING = 0x42, // busy sending
ERR_UNEXPECTED_SENDDONE = 0x43, // sendDone for packet I didn't send
ERR_NO_FREE_PACKET_BUFFER = 0x44, // no free packet buffer (code location {0})
ERR_NO_FREE_TIMER_OR_QUEUE_ENTRY = 0x45, // no free timer or queue entry (code location {0})
ERR_FREEING_UNUSED = 0x46, // freeing unused memory
ERR_FREEING_ERROR = 0x47, // freeing memory unsupported memory
ERR_MSG_UNKNOWN_TYPE = 0x48, // unknown message type {0}
ERR_WRONG_ADDR_TYPE = 0x49, // wrong address type {0} (code location {1})
ERR_PACKET_TOO_LONG = 0x4a, // total packet size is too long, length {1} (code location {0})
ERR_INPUTBUFFER_LENGTH = 0x4b, // input length problem, length={0}
ERR_BOOTED = 0x4c, // booted
ERR_MAXRETRIES_REACHED = 0x4d, // maxretries reached (counter: {0})
ERR_EMPTY_QUEUE_OR_UNKNOWN_TIMER = 0x4e, // empty queue or trying to remove unknown timer id (code location {0})
ERR_PUSH_LOWER_LAYER = 0x4f, // failed to push to lower layer
ERR_INVALID_PARAM = 0x50, // received an invalid parameter
ERR_BUFFER_OVERFLOW = 0x43, // buffer overflow detected (code location {0})
ERR_BUSY_SENDING = 0x44, // busy sending
ERR_UNEXPECTED_SENDDONE = 0x45, // sendDone for packet I didn't send
ERR_NO_FREE_PACKET_BUFFER = 0x46, // no free packet buffer (code location {0})
ERR_NO_FREE_TIMER_OR_QUEUE_ENTRY = 0x47, // no free timer or queue entry (code location {0})
ERR_FREEING_UNUSED = 0x48, // freeing unused memory
ERR_FREEING_ERROR = 0x49, // freeing memory unsupported memory
ERR_MSG_UNKNOWN_TYPE = 0x4a, // unknown message type {0}
ERR_WRONG_ADDR_TYPE = 0x4b, // wrong address type {0} (code location {1})
ERR_PACKET_TOO_LONG = 0x4c, // total packet size is too long, length {0} (adding {1} bytes)
ERR_PACKET_TOO_SHORT = 0x4d, // total packet size is too short, length {0} (removing {1} bytes)
ERR_INPUTBUFFER_LENGTH = 0x4e, // input length problem, length={0}
ERR_BOOTED = 0x4f, // booted
ERR_MAXRETRIES_REACHED = 0x50, // maxretries reached (counter: {0})
ERR_EMPTY_QUEUE_OR_UNKNOWN_TIMER = 0x51, // empty queue or trying to remove unknown timer id (code location {0})
ERR_PUSH_LOWER_LAYER = 0x52, // failed to push to lower layer
ERR_INVALID_PARAM = 0x53, // received an invalid parameter
ERR_COPY_TO_SPKT = 0x54, // copy packet content to small packet (pkt len {} < max len {})
ERR_COPY_TO_BPKT = 0x55, // copy packet content to big packet (pkt len {} > max len {})
};

//=========================== typedef =========================================
Expand Down Expand Up @@ -324,28 +327,33 @@ typedef struct {
uint8_t creator; // the component which called getFreePacketBuffer()
uint8_t owner; // the component which currently owns the entry
uint8_t* payload; // pointer to the start of the payload within 'packet'
uint16_t length; // length in bytes of the payload
int16_t length; // length in bytes of the payload
//l7
#if defined(DEADLINE_OPTION)
uint16_t max_delay; // Max delay in milliseconds before which the packet should be delivered to the receiver
bool orgination_time_flag;
bool drop_flag;
#endif
bool is_cjoin_response;
#if defined(OPENWSN_6LO_FRAGMENTATION_C)
bool is_big_packet;
#endif

//l4
uint8_t l4_protocol; // l4 protocol to be used
bool l4_protocol_compressed; // is the l4 protocol header compressed?
uint16_t l4_sourcePortORicmpv6Type; // l4 source port
uint16_t l4_destination_port; // l4 destination port
uint8_t* l4_payload; // pointer to the start of the payload of l4 (used for retransmits)
uint8_t l4_length; // length of the payload of l4 (used for retransmits)

//l3
open_addr_t l3_destinationAdd; // 128b IPv6 destination (down stack)
open_addr_t l3_sourceAdd; // 128b IPv6 source address
bool l3_useSourceRouting; // TRUE when the packet goes downstream

#if defined(OPENWSN_6LO_FRAGMENTATION_C)
bool l3_isFragment; // TRUE when this is a 6LowPAN fragment
bool l3_isFragment;
#endif
//l2
owerror_t l2_sendDoneError; // outcome of trying to send this packet
Expand Down Expand Up @@ -386,14 +394,14 @@ typedef struct {
uint8_t l1_lqi; // LQI of received packet
bool l1_crc; // did received packet pass CRC check?
//the packet
uint8_t packet[1+1+125+2+1]; // 1B spi address, 1B length, 125B data, 2B CRC, 1B LQI
uint8_t packet[IEEE802154_FRAME_SIZE]; // 1B spi address, 1B length, 125B data, 2B CRC, 1B LQI
} OpenQueueEntry_t;


#if defined(OPENWSN_6LO_FRAGMENTATION_C)
typedef struct {
OpenQueueEntry_t standard_entry;
uint8_t packet_remainder[IPV6_PACKET_SIZE - 130]; // 130 byts alread allocated in the normal OpenQueueEntry
uint8_t packet_remainder[IPV6_PACKET_SIZE - IEEE802154_FRAME_SIZE]; // 127 bytzs alread allocated in the OpenQueueEntry
} OpenQueueBigEntry_t;
#endif

Expand Down
6 changes: 5 additions & 1 deletion openapps/cexample/cexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ void cexample_task_cb(void) {
pkt->creator = COMPONENT_CEXAMPLE;
pkt->owner = COMPONENT_CEXAMPLE;
// CoAP payload
packetfunctions_reserveHeaderSize(pkt, PAYLOADLEN);
if (packetfunctions_reserveHeader(&pkt, PAYLOADLEN) == E_FAIL) {
openqueue_freePacketBuffer(pkt);
return;
}
for (i = 0; i < PAYLOADLEN; i++) {
pkt->payload[i] = i;
}

avg = openrandom_get16b();
pkt->payload[0] = (avg >> 8) & 0xff;
pkt->payload[1] = (avg >> 0) & 0xff;
Expand Down
39 changes: 32 additions & 7 deletions openapps/cinfo/cinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,51 @@ owerror_t cinfo_receive(
//=== prepare CoAP response

// radio name
packetfunctions_reserveHeaderSize(msg, sizeof(infoRadioName) - 1);
if (packetfunctions_reserveHeader(&msg, sizeof(infoRadioName) - 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
memcpy(&msg->payload[0], &infoRadioName, sizeof(infoRadioName) - 1);

// uC name
packetfunctions_reserveHeaderSize(msg, 1);
if (packetfunctions_reserveHeader(&msg, 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
msg->payload[0] = '\n';
packetfunctions_reserveHeaderSize(msg, sizeof(infouCName) - 1);

if (packetfunctions_reserveHeader(&msg, sizeof(infouCName) - 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
memcpy(&msg->payload[0], &infouCName, sizeof(infouCName) - 1);

// board name
packetfunctions_reserveHeaderSize(msg, 1);
if (packetfunctions_reserveHeader(&msg, 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
msg->payload[0] = '\n';
packetfunctions_reserveHeaderSize(msg, sizeof(infoBoardname) - 1);

if (packetfunctions_reserveHeader(&msg, sizeof(infoBoardname) - 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
memcpy(&msg->payload[0], &infoBoardname, sizeof(infoBoardname) - 1);

// stack name and version
packetfunctions_reserveHeaderSize(msg, 1);
if (packetfunctions_reserveHeader(&msg, 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
msg->payload[0] = '\n';
packetfunctions_reserveHeaderSize(msg, sizeof(infoStackName) - 1 + 6);

if (packetfunctions_reserveHeader(&msg, sizeof(infoStackName)) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
memcpy(&msg->payload[0], &infoStackName, sizeof(infoStackName) - 1);

msg->payload[sizeof(infoStackName) - 1 + 6 - 6] = '0' + OPENWSN_VERSION_MAJOR;
msg->payload[sizeof(infoStackName) - 1 + 6 - 5] = '.';
msg->payload[sizeof(infoStackName) - 1 + 6 - 4] = '0' + OPENWSN_VERSION_MINOR / 10;
Expand Down
14 changes: 11 additions & 3 deletions openapps/cjoin/cjoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
\brief Implementation of Constrained Join Protocol (CoJP) from minimal-security-06 draft.
*/

#include "config.h"

#if defined(OPENWSN_CJOIN_C)

#include "opendefs.h"
#include "cjoin.h"
#include "coap.h"
Expand Down Expand Up @@ -233,7 +237,6 @@ void cjoin_task_cb(void) {
// that may be set over the serial
cjoin_init_security_context();


cjoin_sendJoinRequest(joinProxy);
}

Expand Down Expand Up @@ -297,11 +300,15 @@ owerror_t cjoin_sendJoinRequest(open_addr_t *joinProxy) {
join_request.role = COJP_ROLE_VALUE_6N; // regular non-6LBR node
join_request.pan_id = idmanager_getMyID(ADDR_PANID); // pre-configured PAN ID
payload_len = cojp_cbor_encode_join_request_object(tmp, &join_request);
packetfunctions_reserveHeaderSize(pkt, payload_len);

if (packetfunctions_reserveHeader(&pkt, payload_len) == E_FAIL) {
openqueue_freePacketBuffer(pkt);
return E_FAIL;
}
memcpy(pkt->payload, tmp, payload_len);
// send

LOG_VERBOSE(COMPONENT_CJOIN, ERR_JOIN_REQUEST, (errorparameter_t) 0, (errorparameter_t) 0);
LOG_INFO(COMPONENT_CJOIN, ERR_JOIN_REQUEST, (errorparameter_t) 0, (errorparameter_t) 0);

outcome = coap_send(
pkt,
Expand Down Expand Up @@ -357,3 +364,4 @@ void cjoin_setIsJoined(bool newValue) {
}
}

#endif /* OPENWSN_CJOIN_H */
5 changes: 4 additions & 1 deletion openapps/cled/cled.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ owerror_t cled_receive(OpenQueueEntry_t *msg,
msg->length = 0;

// add CoAP payload
packetfunctions_reserveHeaderSize(msg, 1);
if (packetfunctions_reserveHeader(&msg, 1) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return E_FAIL;
}

if (leds_error_isOn() == 1) {
msg->payload[0] = '1';
Expand Down
5 changes: 4 additions & 1 deletion openapps/csensors/csensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ void csensors_fillpayload(OpenQueueEntry_t *msg,
uint16_t value;

value = csensors_vars.csensors_resource[id].opensensors_resource->callbackRead();
packetfunctions_reserveHeaderSize(msg, 2);
if (packetfunctions_reserveHeader(&msg, 2)) == E_FAIL){
openqueue_freePacketBuffer(msg);
return;
}

// add value
msg->payload[0] = (value >> 8) & 0x00ff;
Expand Down
11 changes: 8 additions & 3 deletions openapps/cstorm/cstorm.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ owerror_t cstorm_receive(
msg->length = 0;

// add CoAP payload
packetfunctions_reserveHeaderSize(msg, 2);
if (packetfunctions_reserveHeader(&msg, 2) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
// return as big endian
msg->payload[0] = (uint8_t)(cstorm_vars.period >> 8);
msg->payload[1] = (uint8_t)(cstorm_vars.period & 0xff);
Expand Down Expand Up @@ -211,10 +214,12 @@ void cstorm_task_cb(void) {
pkt->owner = COMPONENT_CSTORM;

//The contents of the message are written in reverse order : the payload first
//packetfunctions_reserveHeaderSize moves the index pkt->payload

// add payload
packetfunctions_reserveHeaderSize(pkt, sizeof(cstorm_payload) - 1);
if (packetfunctions_reserveHeader(&pkt, sizeof(cstorm_payload) - 1) == E_FAIL) {
openqueue_freePacketBuffer(pkt);
return;
}
memcpy(&pkt->payload[0], cstorm_payload, sizeof(cstorm_payload) - 1);

// location-path option
Expand Down
15 changes: 12 additions & 3 deletions openapps/rrt/rrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ owerror_t rrt_receive(

void rrt_setGETRespMsg(OpenQueueEntry_t *msg, uint8_t registered) {
if (registered == 0) {
packetfunctions_reserveHeaderSize(msg, 11);
if (packetfunctions_reserveHeader(&msg, 11) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
msg->payload[0] = 'r';
msg->payload[1] = 'e';
msg->payload[2] = 'g';
Expand All @@ -179,7 +182,10 @@ void rrt_setGETRespMsg(OpenQueueEntry_t *msg, uint8_t registered) {
rrt_sendCoAPMsg('D', NULL); //'D' stands for discovery, 0 for ringmaster

} else {
packetfunctions_reserveHeaderSize(msg, 10);
if (packetfunctions_reserveHeader(&msg, 10) == E_FAIL) {
openqueue_freePacketBuffer(msg);
return;
}
msg->payload[0] = 'r';
msg->payload[1] = 'e';
msg->payload[2] = 'g';
Expand Down Expand Up @@ -213,7 +219,10 @@ void rrt_sendCoAPMsg(char actionMsg, uint8_t *ipv6mote) {
pkt->owner = COMPONENT_RRT;
pkt->l4_protocol = IANA_UDP;

packetfunctions_reserveHeaderSize(pkt, 1);
if (packetfunctions_reserveHeader(&pkt, 1) == E_FAIL) {
openqueue_freePacketBuffer(pkt);
return;
}
pkt->payload[0] = actionMsg;

// location-path option
Expand Down
7 changes: 5 additions & 2 deletions openapps/uecho/uecho.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void uecho_init(void) {
void uecho_receive(OpenQueueEntry_t *request) {
OpenQueueEntry_t *reply;

reply = openqueue_getFreeBigPacketBuffer(COMPONENT_UECHO);
reply = openqueue_getFreePacketBuffer(COMPONENT_UECHO);

if (reply == NULL) {
LOG_ERROR(COMPONENT_UECHO, ERR_NO_FREE_PACKET_BUFFER, (errorparameter_t) 0, (errorparameter_t) 0);
Expand All @@ -50,7 +50,10 @@ void uecho_receive(OpenQueueEntry_t *request) {
// copy source to destination to echo.
memcpy(&reply->l3_destinationAdd.addr_128b[0], &request->l3_sourceAdd.addr_128b[0], 16);

packetfunctions_reserveHeaderSize(reply, request->length);
if (packetfunctions_reserveHeader(&reply, request->length) == E_FAIL) {
openqueue_freePacketBuffer(reply);
return;
}
memcpy(&reply->payload[0], &request->payload[0], request->length);

openqueue_freePacketBuffer(request);
Expand Down
5 changes: 4 additions & 1 deletion openapps/uexpiration/uexpiration.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ void uexpiration_task_cb(void) {
memcpy(&reply->l3_destinationAdd.addr_128b[0], &req.l3_sourceAdd.addr_128b[0], 16);

// Seq number in payload
packetfunctions_reserveHeaderSize(reply, sizeof(uint16_t));
if (packetfunctions_reserveHeader(&reply, sizeof(uint16_t)) == E_FAIL) {
openqueue_freePacketBuffer(reply);
return;
}
reply->payload[1] = (uint8_t)((seqno & 0xff00) >> 8);
reply->payload[0] = (uint8_t)(seqno & 0x00ff);

Expand Down
5 changes: 4 additions & 1 deletion openapps/uexpiration_monitor/uexpiration_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ void umonitor_receive(OpenQueueEntry_t *request) {

/*************** Packet Payload ********************/
// [Expiration time, Delay]
packetfunctions_reserveHeaderSize(reply, (2 * sizeof(uint16_t)));
if (packetfunctions_reserveHeader(&reply, (2 * sizeof(uint16_t))) == E_FAIL) {
openqueue_freePacketBuffer(reply);
return;
}
#ifdef DEADLINE_OPTION_ENABLED
memset(&deadline, 0, sizeof(monitor_expiration_vars_t));
iphc_getDeadlineInfo(&deadline);
Expand Down
Loading

0 comments on commit 479ecc6

Please sign in to comment.