41 #include "contiki-lib.h" 42 #include "lib/assert.h" 51 #define LOG_MODULE "6top" 52 #define LOG_LEVEL LOG_LEVEL_6TOP 54 static void mac_callback(
void *ptr,
int status,
int transmissions);
56 uint8_t sfid, uint8_t seqno,
57 const linkaddr_t *dest_addr);
60 mac_callback(
void *ptr,
int status,
int transmissions)
65 assert(trans != NULL);
67 LOG_ERR(
"6P: mac_callback() fails because trans is NULL\n");
73 switch(current_state) {
74 case SIXP_TRANS_STATE_INIT:
75 new_state = SIXP_TRANS_STATE_REQUEST_SENT;
77 case SIXP_TRANS_STATE_REQUEST_RECEIVED:
78 new_state = SIXP_TRANS_STATE_RESPONSE_SENT;
80 case SIXP_TRANS_STATE_RESPONSE_RECEIVED:
81 new_state = SIXP_TRANS_STATE_CONFIRMATION_SENT;
84 LOG_ERR(
"6P: mac_callback() fails because of an unexpected state (%u)\n",
95 if(current_state == SIXP_TRANS_STATE_INIT) {
97 new_state = SIXP_TRANS_STATE_TERMINATING;
100 new_state = current_state;
104 if(new_state != current_state &&
106 LOG_ERR(
"6P: mac_callback() fails because of state transition failure\n");
107 LOG_ERR(
"6P: something wrong; we're terminating the trans %p\n", trans);
121 uint8_t sfid, uint8_t seqno,
122 const linkaddr_t *dest_addr)
126 LOG_ERR(
"6P: failed to create a 6P packet to return an error [rc:%u]\n",
136 sixp_input(
const uint8_t *buf, uint16_t len,
const linkaddr_t *src_addr)
145 assert(buf != NULL && src_addr != NULL);
146 if(buf == NULL || src_addr == NULL) {
151 if(pkt.
version != SIXP_PKT_VERSION) {
152 LOG_ERR(
"6P: sixp_input() unsupported version %u\n", pkt.
version);
157 LOG_ERR(
"6P: sixp_input() fails to send RC_ERR_VERSION\n");
161 LOG_ERR(
"6P: sixp_input() fails because of a malformed 6P packet\n");
168 LOG_ERR(
"6P: sixp_input() fails because of unsupported type [type:%u]\n",
174 LOG_ERR(
"6P: sixp_input() fails because SF [sfid:%u] is unavailable\n",
183 LOG_ERR(
"6P: sixp_input() fails to return an error response\n");
194 LOG_ERR(
"6P: sixp_input() fails because another request [peer_addr:");
195 LOG_ERR_LLADDR((
const linkaddr_t *)src_addr);
200 LOG_ERR(
"6P: sixp_input() fails to return an error response");
207 LOG_INFO(
"6P: sixp_input() reset nbr's next_seqno by CLEAR Request\n");
212 LOG_ERR(
"6P: sixp_input() fails because of lack of memory\n");
216 LOG_ERR(
"6P: sixp_input() fails to return an error response\n");
230 SIXP_TRANS_STATE_REQUEST_RECEIVED);
238 LOG_ERR(
"6P: sixp_input() fails to return an error response\n");
247 LOG_ERR(
"6P: sixp_input() fails because of no trans [peer_addr:");
248 LOG_ERR_LLADDR((
const linkaddr_t *)src_addr);
252 seqno != pkt.
seqno) {
253 LOG_ERR(
"6P: sixp_input() fails because of invalid seqno [seqno:%u, %u]\n",
260 assert(trans != NULL);
264 SIXP_TRANS_STATE_REQUEST_RECEIVED);
268 SIXP_TRANS_STATE_RESPONSE_RECEIVED);
272 SIXP_TRANS_STATE_CONFIRMATION_RECEIVED);
275 LOG_ERR(
"6P: sixp_input() fails because of unsupported type [type:%u]\n",
280 LOG_ERR(
"6P: sixp_input() fails because of state transition failure\n");
281 LOG_ERR(
"6P: something wrong; we're terminating the trans %p\n", trans);
286 if(sf->
input != NULL) {
295 const uint8_t *body, uint16_t body_len,
296 const linkaddr_t *dest_addr,
305 assert(dest_addr != NULL);
311 LOG_ERR(
"6P: sixp_output() fails because another trans for [peer_addr:");
312 LOG_ERR_LLADDR((
const linkaddr_t *)dest_addr);
313 LOG_ERR_(
"] is in process\n");
321 LOG_ERR(
"6P: sixp_output() fails because of no transaction [peer_addr:");
322 LOG_ERR_LLADDR((
const linkaddr_t *)dest_addr);
326 SIXP_TRANS_STATE_REQUEST_RECEIVED) {
327 LOG_ERR(
"6P: sixp_output() fails because of invalid transaction state\n");
334 LOG_ERR(
"6P: sixp_output() fails because of no transaction [peer_addr:");
335 LOG_ERR_LLADDR((
const linkaddr_t *)dest_addr);
339 SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
340 LOG_ERR(
"6P: sixp_output() fails because of invalid transaction state\n");
346 LOG_ERR(
"6P: sixp_output() fails because of unsupported type [type:%u]\n",
362 LOG_ERR(
"6P: sixp_output() fails because of no memory for another nbr\n");
370 LOG_ERR(
"6P: sixp_output() fails because it fails to allocate a nbr\n");
374 LOG_ERR(
"6P: sixp_output() fails to get the next sequence number\n");
378 LOG_INFO(
"6P: sixp_output() reset nbr's next_seqno by CLEAR Request\n");
382 assert(trans != NULL);
384 LOG_ERR(
"6P: sixp_output() fails because it fails to get seqno\n");
394 LOG_ERR(
"6P: sixp_output() fails to create a 6P packet\n");
400 assert(trans == NULL);
402 LOG_ERR(
"6P: sixp_output() is aborted because of no memory\n");
409 assert(trans != NULL);
Transaction Management APIs for 6top Protocol (6P)
sixp_pkt_cmd_t
6P Command Identifiers
sixp_pkt_type_t
6P Message Types
struct sixp_nbr sixp_nbr_t
6P Neighbor Data Structure (for internal use)
int sixp_trans_init(void)
Initialize Memory and List for 6P transactions This function removes and frees existing transactions...
/brief Scheduling Function Driver
sixp_pkt_code_t code
Code.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
int sixp_nbr_reset_next_seqno(sixp_nbr_t *nbr)
Reset the next sequence number of a neighbor to zero.
void sixp_trans_set_callback(sixp_trans_t *trans, sixp_sent_callback_t func, void *arg, uint16_t arg_len)
Set an output callback to a specified transaction.
uint16_t body_len
The length of Other Fields.
const sixtop_sf_t * sixtop_find_sf(uint8_t sfid)
Find a SF which has been added by SFID.
Neighbor Management APIs for 6top Protocol (6P)
void sixp_trans_invoke_callback(sixp_trans_t *trans, sixp_output_status_t status)
Invoke the output callback of a specified transaction.
struct sixp_trans sixp_trans_t
6P Transaction Data Structure (for internal use)
uint8_t value
8-bit unsigned integer value
The MAC layer transmission was OK.
sixp_pkt_cmd_t sixp_trans_get_cmd(sixp_trans_t *trans)
Return the command associated with a specified transaction.
sixtop_sf_input input
Input Handler.
6P Codes integrating Command IDs and Return Codes
sixp_trans_t * sixp_trans_find(const linkaddr_t *peer_addr)
Find a transaction.
void(* sixp_sent_callback_t)(void *arg, uint16_t arg_len, const linkaddr_t *dest_addr, sixp_output_status_t status)
6P Packet Sent Handler
const uint8_t * body
Other Fields...
sixp_trans_state_t sixp_trans_get_state(sixp_trans_t *trans)
Return the state of a specified transaction.
void sixtop_output(const linkaddr_t *dest_addr, mac_callback_t callback, void *arg)
Output a 6P packet which is supposestored in packetbuf.
sixp_pkt_type_t type
Type.
sixp_nbr_t * sixp_nbr_alloc(const linkaddr_t *addr)
Allocate a neighbor.
6TiSCH Operation Sublayer (6top) APIs
int sixp_output(sixp_pkt_type_t type, sixp_pkt_code_t code, uint8_t sfid, const uint8_t *body, uint16_t body_len, const linkaddr_t *dest_addr, sixp_sent_callback_t func, void *arg, uint16_t arg_len)
Output a 6P packet.
void sixp_init(void)
Initialize 6P Module It invokes sixp_nbr_init() and sixp_trans_init().
6top Protocol (6P) Packet Manipulation APIs
int sixp_nbr_init(void)
Initialize 6p Neighbor Table.
int sixp_pkt_parse(const uint8_t *buf, uint16_t len, sixp_pkt_t *pkt)
Parse a 6P packet.
sixp_trans_state_t
6P Transaction States (for internal use)
sixp_pkt_cmd_t cmd
6P Command Identifier
int16_t sixp_trans_get_seqno(sixp_trans_t *trans)
Return the sequence number associated with a specified transaction.
int sixp_nbr_get_next_seqno(sixp_nbr_t *nbr)
Get the next sequence number of a neighbor.
sixp_nbr_t * sixp_nbr_find(const linkaddr_t *addr)
Find a neighbor.
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.
sixp_trans_t * sixp_trans_alloc(const sixp_pkt_t *pkt, const linkaddr_t *peer_addr)
Allocate a transaction.
void sixp_input(const uint8_t *buf, uint16_t len, const linkaddr_t *src_addr)
Input a 6P packet.
int sixp_trans_transit_state(sixp_trans_t *trans, sixp_trans_state_t new_state)
Change the state of a specified transaction.
Header file for the logging system
sixp_pkt_version_t version
Version.