44 #include "contiki-lib.h" 45 #include "lib/assert.h" 54 #define LOG_MODULE "6top" 55 #define LOG_LEVEL LOG_LEVEL_6TOP 92 return sizeof(sixp_pkt_metadata_t);
104 return sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t);
115 return sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t);
125 return (
sizeof(sixp_pkt_metadata_t) +
126 sizeof(sixp_pkt_cell_options_t) +
127 sizeof(sixp_pkt_reserved_t));
137 return (
sizeof(sixp_pkt_metadata_t) +
138 sizeof(sixp_pkt_cell_options_t) +
139 sizeof(sixp_pkt_reserved_t) +
140 sizeof(sixp_pkt_offset_t));
150 return (
sizeof(sixp_pkt_metadata_t) +
151 sizeof(sixp_pkt_cell_options_t) +
152 sizeof(sixp_pkt_num_cells_t));
166 return (
sizeof(sixp_pkt_metadata_t) +
167 sizeof(sixp_pkt_cell_options_t) +
168 sizeof(sixp_pkt_num_cells_t));
186 return sizeof(sixp_pkt_metadata_t);
197 sixp_pkt_metadata_t metadata,
198 uint8_t *body, uint16_t body_len)
203 LOG_ERR(
"6P-pkt: cannot set metadata; body is null\n");
207 if((offset = get_metadata_offset(type, code)) < 0) {
208 LOG_ERR(
"6P-pkt: cannot set metadata [type=%u, code=%u], invalid type\n",
213 if(body_len < (offset +
sizeof(metadata))) {
214 LOG_ERR(
"6P-pkt: cannot set metadata, body is too short [body_len=%u]\n",
223 memcpy(body + offset, &metadata,
sizeof(metadata));
230 sixp_pkt_metadata_t *metadata,
231 const uint8_t *body, uint16_t body_len)
235 if(metadata == NULL || body == NULL) {
236 LOG_ERR(
"6P-pkt: cannot get metadata; invalid argument\n");
240 if((offset = get_metadata_offset(type, code)) < 0) {
241 LOG_ERR(
"6P-pkt: cannot get metadata [type=%u, code=%u], invalid type\n",
246 if(body_len < offset +
sizeof(*metadata)) {
247 LOG_ERR(
"6P-pkt: cannot get metadata [type=%u, code=%u], ",
249 LOG_ERR_(
"body is too short\n");
257 memcpy(metadata, body + offset,
sizeof(*metadata));
264 sixp_pkt_cell_options_t cell_options,
265 uint8_t *body, uint16_t body_len)
270 LOG_ERR(
"6P-pkt: cannot set cell_options; body is null\n");
274 if((offset = get_cell_options_offset(type, code)) < 0) {
275 LOG_ERR(
"6P-pkt: cannot set cell_options [type=%u, code=%u], ",
277 LOG_ERR_(
"invalid type\n");
281 if(body_len < (offset +
sizeof(cell_options))) {
282 LOG_ERR(
"6P-pkt: cannot set cell_options, ");
283 LOG_ERR_(
"body is too short [body_len=%u]\n", body_len);
288 memcpy(body + offset, &cell_options,
sizeof(uint8_t));
295 sixp_pkt_cell_options_t *cell_options,
296 const uint8_t *body, uint16_t body_len)
300 if(cell_options == NULL || body == NULL) {
301 LOG_ERR(
"6P-pkt: cannot get cell_options; invalid argument\n");
305 if((offset = get_cell_options_offset(type, code)) < 0) {
306 LOG_ERR(
"6P-pkt: cannot get cell_options [type=%u, code=%u]",
308 LOG_ERR_(
"invalid type\n");
312 if(body_len < (offset +
sizeof(*cell_options))) {
313 LOG_ERR(
"6P-pkt: cannot get cell_options, ");
314 LOG_ERR_(
"body is too short [body_len=%u]\n", body_len);
319 memcpy(cell_options, body + offset,
sizeof(uint8_t));
326 sixp_pkt_num_cells_t num_cells,
327 uint8_t *body, uint16_t body_len)
332 LOG_ERR(
"6P-pkt: cannot set num_cells; body is null\n");
336 if((offset = get_num_cells_offset(type, code)) < 0) {
337 LOG_ERR(
"6P-pkt: cannot set num_cells; ");
338 LOG_ERR_(
"packet [type=%u, code=%u] won't have NumCells\n",
343 memcpy(body + offset, &num_cells,
sizeof(uint8_t));
350 sixp_pkt_num_cells_t *num_cells,
351 const uint8_t *body, uint16_t body_len)
355 if(num_cells == NULL || body == NULL) {
356 LOG_ERR(
"6P-pkt: cannot get num_cells; invalid argument\n");
360 if((offset = get_num_cells_offset(type, code)) < 0) {
361 LOG_ERR(
"6P-pkt: cannot get num_cells; ");
362 LOG_ERR_(
"packet [type=%u, code=%u] won't have NumCells\n",
367 if(body_len < (offset +
sizeof(*num_cells))) {
368 LOG_ERR(
"6P-pkt: cannot get num_cells; body is too short\n");
373 memcpy(num_cells, body + offset,
sizeof(uint8_t));
380 sixp_pkt_reserved_t reserved,
381 uint8_t *body, uint16_t body_len)
386 LOG_ERR(
"6P-pkt: cannot set reserved; body is null\n");
390 if((offset = get_reserved_offset(type, code)) < 0) {
391 LOG_ERR(
"6P-pkt: cannot set reserved; ");
392 LOG_ERR_(
"packet [type=%u, code=%u] won't have Reserved\n",
397 if(body_len < (offset +
sizeof(reserved))) {
398 LOG_ERR(
"6P-pkt: cannot set reserved; body is too short\n");
403 memcpy(body + offset, &reserved,
sizeof(uint8_t));
410 sixp_pkt_reserved_t *reserved,
411 const uint8_t *body, uint16_t body_len)
415 if(reserved == NULL || body == NULL) {
416 LOG_ERR(
"6P-pkt: cannot get reserved; invalid argument\n");
420 if((offset = get_reserved_offset(type, code)) < 0) {
421 LOG_ERR(
"6P-pkt: cannot get reserved; ");
422 LOG_ERR_(
"packet [type=%u, code=%u] won't have Reserved\n",
428 memcpy(reserved, body + offset,
sizeof(uint8_t));
435 sixp_pkt_offset_t cell_offset,
436 uint8_t *body, uint16_t body_len)
441 LOG_ERR(
"6P-pkt: cannot set offset; invalid argument\n");
445 if((offset = get_offset_offset(type, code)) < 0) {
446 LOG_ERR(
"6P-pkt: cannot set offset; ");
447 LOG_ERR_(
"packet [type=%u, code=%u] won't have Offset\n",
452 if(body_len < (offset +
sizeof(cell_offset))) {
453 LOG_ERR(
"6P-pkt: cannot set offset; body is too short\n");
461 (body + offset)[0] = *((uint16_t *)&cell_offset) & 0xff;
462 (body + offset)[1] = (*((uint16_t *)&cell_offset) >> 8) & 0xff;
469 sixp_pkt_offset_t *cell_offset,
470 const uint8_t *body, uint16_t body_len)
475 if(cell_offset == NULL || body == NULL) {
476 LOG_ERR(
"6P-pkt: cannot get offset; invalid argument\n");
480 if((offset = get_offset_offset(type, code)) < 0) {
481 LOG_ERR(
"6P-pkt: cannot get offset; ");
482 LOG_ERR_(
"packet [type=%u, code=%u] won't have Offset\n",
487 if(body_len < (offset +
sizeof(*cell_offset))) {
488 LOG_ERR(
"6P-pkt: cannot get offset; body is too short\n");
497 *((uint16_t *)cell_offset) = p[0] + (p[1] << 8);
504 sixp_pkt_max_num_cells_t max_num_cells,
505 uint8_t *body, uint16_t body_len)
510 LOG_ERR(
"6P-pkt: cannot set max_num_cells; invalid argument\n");
514 if((offset = get_max_num_cells_offset(type, code)) < 0) {
515 LOG_ERR(
"6P-pkt: cannot set max_num_cells; ");
516 LOG_ERR_(
"packet [type=%u, code=%u] won't have MaxNumCells\n",
521 if(body_len < (offset +
sizeof(max_num_cells))) {
522 LOG_ERR(
"6P-pkt: cannot set max_num_cells; body is too short\n");
530 (body + offset)[0] = *((uint16_t *)&max_num_cells) & 0xff;
531 (body + offset)[1] = (*((uint16_t *)&max_num_cells) >> 8) & 0xff;
538 sixp_pkt_max_num_cells_t *max_num_cells,
539 const uint8_t *body, uint16_t body_len)
544 if(max_num_cells == NULL || body == NULL) {
545 LOG_ERR(
"6P-pkt: cannot get max_num_cells; invalid argument\n");
549 if((offset = get_max_num_cells_offset(type, code)) < 0) {
550 LOG_ERR(
"6P-pkt: cannot get max_num_cells; ");
551 LOG_ERR_(
"packet [type=%u, code=%u] won't have MaxNumCells\n",
556 if(body_len < (offset +
sizeof(*max_num_cells))) {
557 LOG_ERR(
"6P-pkt: cannot get max_num_cells; body is too short\n");
566 *((uint16_t *)max_num_cells) = p[0] + (p[1] << 8);
573 const uint8_t *cell_list,
574 uint16_t cell_list_len,
575 uint16_t cell_offset,
576 uint8_t *body, uint16_t body_len)
580 if(cell_list == NULL || body == NULL) {
581 LOG_ERR(
"6P-pkt: cannot set cell_list; invalid argument\n");
585 if((offset = get_cell_list_offset(type, code)) < 0) {
586 LOG_ERR(
"6P-pkt: cannot set cell_list; ");
587 LOG_ERR_(
"packet [type=%u, code=%u] won't have CellList\n",
592 offset += cell_offset;
594 if(body_len < (offset + cell_list_len)) {
595 LOG_ERR(
"6P-pkt: cannot set cell_list; body is too short\n");
597 }
else if((cell_list_len %
sizeof(sixp_pkt_cell_t)) != 0) {
598 LOG_ERR(
"6P-pkt: cannot set cell_list; invalid {body, cell_list}_len\n");
602 memcpy(body + offset, cell_list, cell_list_len);
609 const uint8_t **cell_list,
610 sixp_pkt_offset_t *cell_list_len,
611 const uint8_t *body, uint16_t body_len)
615 if(cell_list_len == NULL || body == NULL) {
616 LOG_ERR(
"6P-pkt: cannot get cell_list\n");
620 if((offset = get_cell_list_offset(type, code)) < 0) {
621 LOG_ERR(
"6P-pkt: cannot get cell_list; ");
622 LOG_ERR_(
"packet [type=%u, code=%u] won't have CellList\n",
627 if(body_len < offset) {
628 LOG_ERR(
"6P-pkt: cannot set cell_list; body is too short\n");
630 }
else if(((body_len - offset) %
sizeof(sixp_pkt_cell_t)) != 0) {
631 LOG_ERR(
"6P-pkt: cannot set cell_list; invalid {body, cell_list}_len\n");
635 if(cell_list != NULL) {
636 *cell_list = body + offset;
639 *cell_list_len = body_len - offset;
646 const uint8_t *rel_cell_list,
647 uint16_t rel_cell_list_len,
648 uint16_t cell_offset,
649 uint8_t *body, uint16_t body_len)
652 sixp_pkt_num_cells_t num_cells;
654 if(rel_cell_list == NULL || body == NULL) {
655 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; invalid argument\n");
660 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; no NumCells field\n");
664 if((offset = get_rel_cell_list_offset(type, code)) < 0) {
665 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; ");
666 LOG_ERR_(
"packet [type=%u, code=%u] won't have RelCellList\n",
671 offset += cell_offset;
673 if(body_len < (offset + rel_cell_list_len)) {
674 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; body is too short\n");
676 }
else if((offset + rel_cell_list_len) >
677 (offset + num_cells *
sizeof(sixp_pkt_cell_t))) {
678 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; RelCellList is too long\n");
680 }
else if((rel_cell_list_len %
sizeof(sixp_pkt_cell_t)) != 0) {
681 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; invalid body_len\n");
685 memcpy(body + offset, rel_cell_list, rel_cell_list_len);
692 const uint8_t **rel_cell_list,
693 sixp_pkt_offset_t *rel_cell_list_len,
694 const uint8_t *body, uint16_t body_len)
697 sixp_pkt_num_cells_t num_cells;
699 if(rel_cell_list_len == NULL || body == NULL) {
700 LOG_ERR(
"6P-pkt: cannot get rel_cell_list; invalid argument\n");
705 LOG_ERR(
"6P-pkt: cannot get rel_cell_list; no NumCells field\n");
709 if((offset = get_rel_cell_list_offset(type, code)) < 0) {
710 LOG_ERR(
"6P-pkt: cannot get rel_cell_list; ");
711 LOG_ERR_(
"packet [type=%u, code=%u] won't have RelCellList\n",
716 if(body_len < (offset + (num_cells *
sizeof(sixp_pkt_cell_t)))) {
717 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; body is too short\n");
719 }
else if(((body_len - offset) %
sizeof(sixp_pkt_cell_t)) != 0) {
720 LOG_ERR(
"6P-pkt: cannot set rel_cell_list; invalid body_len\n");
724 if(rel_cell_list != NULL) {
725 *rel_cell_list = body + offset;
728 *rel_cell_list_len = num_cells *
sizeof(sixp_pkt_cell_t);
735 const uint8_t *cand_cell_list,
736 uint16_t cand_cell_list_len,
737 uint16_t cell_offset,
738 uint8_t *body, uint16_t body_len)
741 sixp_pkt_num_cells_t num_cells;
743 if(cand_cell_list == NULL || body == NULL) {
744 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; invalid argument\n");
749 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; no NumCells field\n");
753 if((offset = get_rel_cell_list_offset(type, code)) < 0) {
754 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; ");
755 LOG_ERR_(
"packet [type=%u, code=%u] won't have RelCellList\n",
760 offset += cell_offset + num_cells *
sizeof(sixp_pkt_cell_t);
762 if(body_len < (offset + cand_cell_list_len)) {
763 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; body is too short\n");
765 }
else if((cand_cell_list_len %
sizeof(sixp_pkt_cell_t)) != 0) {
766 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; invalid body_len\n");
770 memcpy(body + offset, cand_cell_list, cand_cell_list_len);
777 const uint8_t **cand_cell_list,
778 sixp_pkt_offset_t *cand_cell_list_len,
779 const uint8_t *body, uint16_t body_len)
782 sixp_pkt_num_cells_t num_cells;
784 if(cand_cell_list_len == NULL || body == NULL) {
785 LOG_ERR(
"6P-pkt: cannot get cand_cell_list; invalid argument\n");
790 LOG_ERR(
"6P-pkt: cannot get cand_cell_list; no NumCells field\n");
794 if((offset = get_rel_cell_list_offset(type, code)) < 0) {
795 LOG_ERR(
"6P-pkt: cannot get cand_cell_list; ");
796 LOG_ERR_(
"packet [type=%u, code=%u] won't have RelCellList\n",
801 offset += num_cells *
sizeof(sixp_pkt_cell_t);
803 if(body_len < offset) {
804 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; body is too short\n");
806 }
else if(((body_len - offset) %
sizeof(sixp_pkt_cell_t)) != 0) {
807 LOG_ERR(
"6P-pkt: cannot set cand_cell_list; invalid body_len\n");
811 if(cand_cell_list != NULL) {
812 *cand_cell_list = body + offset;
815 *cand_cell_list_len = body_len - offset;
822 sixp_pkt_total_num_cells_t total_num_cells,
823 uint8_t *body, uint16_t body_len)
828 LOG_ERR(
"6P-pkt: cannot set num_cells; body is null\n");
832 if((offset = get_total_num_cells_offset(type, code)) < 0) {
833 LOG_ERR(
"6P-pkt: cannot set total_num_cells; ");
834 LOG_ERR_(
"packet [type=%u, code=%u] won't have TotalNumCells\n",
842 body[offset] = (uint8_t)(total_num_cells & 0xff);
843 body[offset + 1] = (uint8_t)(total_num_cells >> 8);
850 sixp_pkt_total_num_cells_t *total_num_cells,
851 const uint8_t *body, uint16_t body_len)
855 if(total_num_cells == NULL || body == NULL) {
856 LOG_ERR(
"6P-pkt: cannot get num_cells; invalid argument\n");
860 if((offset = get_total_num_cells_offset(type, code)) < 0) {
861 LOG_ERR(
"6P-pkt: cannot get num_cells; ");
862 LOG_ERR_(
"packet [type=%u, code=%u] won't have TotalNumCells\n",
867 if(body_len < (offset +
sizeof(sixp_pkt_total_num_cells_t))) {
868 LOG_ERR(
"6P-pkt: cannot get num_cells; body is too short\n");
873 *total_num_cells = body[0];
874 *total_num_cells += ((uint16_t)body[1]) << 8;
881 const uint8_t *payload, uint16_t payload_len,
882 uint8_t *body, uint16_t body_len)
887 LOG_ERR(
"6P-pkt: cannot set metadata; body is null\n");
891 if((offset = get_payload_offset(type, code)) < 0) {
892 LOG_ERR(
"6P-pkt: cannot set payload [type=%u, code=%u], invalid type\n",
897 if(body_len < (offset + payload_len)) {
898 LOG_ERR(
"6P-pkt: cannot set payload, body is too short [body_len=%u]\n",
907 memcpy(body + offset, payload, payload_len);
914 uint8_t *buf, uint16_t buf_len,
915 const uint8_t *body, uint16_t body_len)
919 if(buf == NULL || body == NULL) {
920 LOG_ERR(
"6P-pkt: cannot get payload; invalid argument\n");
924 if((offset = get_payload_offset(type, code)) < 0) {
925 LOG_ERR(
"6P-pkt: cannot get payload [type=%u, code=%u], invalid type\n",
930 if((body_len - offset) > buf_len) {
931 LOG_ERR(
"6P-pkt: cannot get payload [type=%u, code=%u], ",
933 LOG_ERR_(
"buf_len is too short\n");
941 memcpy(buf, body + offset, buf_len);
950 assert(buf != NULL && pkt != NULL);
951 if(buf == NULL || pkt == NULL) {
952 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid argument\n");
960 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because it's a too short packet\n");
966 pkt->
type = (buf[0] & 0x30) >> 4;
974 LOG_INFO(
"6P-pkt: sixp_pkt_parse() is processing [type:%u, code:%u, len:%u]\n",
983 if(len < (
sizeof(sixp_pkt_metadata_t) +
984 sizeof(sixp_pkt_cell_options_t) +
985 sizeof(sixp_pkt_num_cells_t)) ||
986 (len %
sizeof(uint32_t)) != 0) {
987 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
992 if(len < (
sizeof(sixp_pkt_metadata_t) +
993 sizeof(sixp_pkt_cell_options_t) +
994 sizeof(sixp_pkt_num_cells_t)) ||
995 (len %
sizeof(uint32_t)) != 0) {
996 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1001 if(len != (
sizeof(sixp_pkt_metadata_t) +
1002 sizeof(sixp_pkt_cell_options_t))) {
1003 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1008 if(len != (
sizeof(sixp_pkt_metadata_t) +
1009 sizeof(sixp_pkt_cell_options_t) +
1010 sizeof(sixp_pkt_reserved_t) +
1011 sizeof(sixp_pkt_offset_t) +
1012 sizeof(sixp_pkt_max_num_cells_t))) {
1013 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1018 if(len <
sizeof(sixp_pkt_metadata_t)) {
1019 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1024 if(len !=
sizeof(sixp_pkt_metadata_t)) {
1025 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1030 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of unsupported cmd\n");
1047 if((len %
sizeof(uint32_t)) != 0) {
1048 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1061 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of invalid length\n");
1066 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of unsupported code\n");
1070 LOG_ERR(
"6P-pkt: sixp_pkt_parse() fails because of unsupported type\n");
1082 uint8_t sfid, uint8_t seqno,
1083 const uint8_t *body, uint16_t body_len,
sixp_pkt_t *pkt)
1087 assert((body == NULL && body_len == 0) || (body != NULL && body_len > 0));
1088 if((body == NULL && body_len > 0) || (body != NULL && body_len == 0)) {
1089 LOG_ERR(
"6P-pkt: sixp_pkt_create() fails because of invalid argument\n");
1100 LOG_ERR(
"6P-pkt: sixp_pkt_create() fails because body is too long\n");
1105 LOG_ERR(
"6P-pkt: sixp_pkt_create fails to allocate header space\n");
1110 hdr[0] = (type << 4) | SIXP_PKT_VERSION;
1111 hdr[1] = code.
value;
1116 if(body_len > 0 && body != NULL) {
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int sixp_pkt_get_metadata(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_metadata_t *metadata, const uint8_t *body, uint16_t body_len)
Read Metadata stored in "Other Fields" of 6P packet.
sixp_pkt_type_t
6P Message Types
int sixp_pkt_get_reserved(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_reserved_t *reserved, const uint8_t *body, uint16_t body_len)
Read Reserved in "Other Fields" of 6P packet.
sixp_pkt_code_t code
Code.
int sixp_pkt_get_cand_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t **cand_cell_list, sixp_pkt_offset_t *cand_cell_list_len, const uint8_t *body, uint16_t body_len)
Read CandCellList in "Other Fields" of 6P packet.
void packetbuf_clear(void)
Clear and reset the packetbuf.
int sixp_pkt_set_cell_options(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_cell_options_t cell_options, uint8_t *body, uint16_t body_len)
Write CellOptions in "Other Fields" of 6P packet.
int sixp_pkt_get_payload(sixp_pkt_type_t type, sixp_pkt_code_t code, uint8_t *buf, uint16_t buf_len, const uint8_t *body, uint16_t body_len)
Read Payload in "Other Fields" of 6P packet.
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
int sixp_pkt_get_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_num_cells_t *num_cells, const uint8_t *body, uint16_t body_len)
Read NumCells in "Other Fields" of 6P packet.
uint16_t body_len
The length of Other Fields.
sixp_pkt_rc_t rc
6P Return Code
int sixp_pkt_get_cell_options(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_cell_options_t *cell_options, const uint8_t *body, uint16_t body_len)
Read CellOptions in "Other Fields" of 6P packet.
int sixp_pkt_set_total_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_total_num_cells_t total_num_cells, uint8_t *body, uint16_t body_len)
Write TotalNumCells in "Other Fields" of 6P packet.
int sixp_pkt_get_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t **cell_list, sixp_pkt_offset_t *cell_list_len, const uint8_t *body, uint16_t body_len)
Read CellList in "Other Fields" of 6P packet.
int sixp_pkt_set_cand_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t *cand_cell_list, uint16_t cand_cell_list_len, uint16_t cell_offset, uint8_t *body, uint16_t body_len)
Write CandCellList in "Other Fields" of 6P packet.
uint8_t value
8-bit unsigned integer value
int sixp_pkt_set_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_num_cells_t num_cells, uint8_t *body, uint16_t body_len)
Write NumCells in "Other Fields" of 6P packet.
int sixp_pkt_get_offset(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_offset_t *cell_offset, const uint8_t *body, uint16_t body_len)
Read Offset in "Other Fields" of 6P packet.
int sixp_pkt_get_rel_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t **rel_cell_list, sixp_pkt_offset_t *rel_cell_list_len, const uint8_t *body, uint16_t body_len)
Read RelCellList in "Other Fields" of 6P packet.
6P Codes integrating Command IDs and Return Codes
int sixp_pkt_set_payload(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t *payload, uint16_t payload_len, uint8_t *body, uint16_t body_len)
Write Payload in "Other Fields" of 6P packet.
int sixp_pkt_get_max_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_max_num_cells_t *max_num_cells, const uint8_t *body, uint16_t body_len)
Read MaxNumCells in "Other Fields" of 6P packet.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
int sixp_pkt_set_max_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_max_num_cells_t max_num_cells, uint8_t *body, uint16_t body_len)
Write MaxNumCells in "Other Fields" of 6P packet.
int sixp_pkt_set_offset(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_offset_t cell_offset, uint8_t *body, uint16_t body_len)
Write Offset in "Other Fields" of 6P packet.
const uint8_t * body
Other Fields...
Main API declarations for TSCH.
int sixp_pkt_set_rel_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t *rel_cell_list, uint16_t rel_cell_list_len, uint16_t cell_offset, uint8_t *body, uint16_t body_len)
Write RelCellList in "Other Fields" of 6P packet.
sixp_pkt_type_t type
Type.
int sixp_pkt_set_metadata(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_metadata_t metadata, uint8_t *body, uint16_t body_len)
Write Metadata into "Other Fields" of 6P packet.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
6top Protocol (6P) Packet Manipulation APIs
int sixp_pkt_parse(const uint8_t *buf, uint16_t len, sixp_pkt_t *pkt)
Parse a 6P packet.
int sixp_pkt_get_total_num_cells(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_total_num_cells_t *total_num_cells, const uint8_t *body, uint16_t body_len)
Read TotalNumCells in "Other Fields" of 6P packet.
int sixp_pkt_set_cell_list(sixp_pkt_type_t type, sixp_pkt_code_t code, const uint8_t *cell_list, uint16_t cell_list_len, uint16_t cell_offset, uint8_t *body, uint16_t body_len)
Write CellList in "Other Fields" of 6P packet.
sixp_pkt_cmd_t cmd
6P Command Identifier
int sixp_pkt_create(sixp_pkt_type_t type, sixp_pkt_code_t code, uint8_t sfid, uint8_t seqno, const uint8_t *body, uint16_t body_len, sixp_pkt_t *pkt)
Create a 6P packet.
Header file for the Packet buffer (packetbuf) management
Header file for the logging system
int sixp_pkt_set_reserved(sixp_pkt_type_t type, sixp_pkt_code_t code, sixp_pkt_reserved_t reserved, uint8_t *body, uint16_t body_len)
Write Reserved in "Other Fields" of 6P packet.
sixp_pkt_version_t version
Version.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.