|
libschc
|
#include <math.h>#include <string.h>#include <stdio.h>#include "schc_config.h"#include "compressor.h"#include "fragmenter.h"#include "schc.h"Functions | |
| static uint16_t | get_fcn_value (uint8_t *fragment, schc_fragmentation_t *conn) |
| get the FCN value More... | |
| static uint16_t | get_max_fcn_value (schc_fragmentation_t *conn) |
| get the ALL-1 FCN value More... | |
| static uint8_t | get_padding_length (uint8_t byte) |
| get the number of zero bits added to the end of the buffer More... | |
| static uint32_t | get_bit_mask (uint8_t len) |
| get a bitmap mask for a number of bits More... | |
| static void | mbuf_print (schc_mbuf_t *head) |
| print the complete mbuf chain More... | |
| static int8_t | mbuf_push (schc_mbuf_t **head, uint8_t *data, uint16_t len) |
| add an item to the end of the mbuf list if head is NULL, the first item of the list will be set More... | |
| static schc_mbuf_t * | get_prev_mbuf (schc_mbuf_t *head, schc_mbuf_t *mbuf) |
| returns the last chain in the mbuf linked list More... | |
| static void | mbuf_delete (schc_mbuf_t **head, schc_mbuf_t *mbuf) |
| delete a mbuf from the chain More... | |
| static uint8_t | mbuf_overwrite (schc_mbuf_t **head, uint16_t frag, schc_mbuf_t *mbuf) |
| check if an mbuf with the same fragment number already exists and overwrite if so More... | |
| uint16_t | get_mbuf_len (schc_mbuf_t *head) |
| returns the total length of the mbuf More... | |
| static schc_mbuf_t * | get_mbuf_tail (schc_mbuf_t *head) |
| returns the last chain in the mbuf linked list More... | |
| void | mbuf_copy (schc_mbuf_t *head, uint8_t *ptr) |
| copy the byte alligned contents of the mbuf chain to the passed pointer More... | |
| void | mbuf_clean (schc_mbuf_t **head) |
| delete all fragments chained in an mbuf More... | |
| static void | mbuf_sort (schc_mbuf_t **head) |
| sort the complete mbuf chain based on fragment counter (fcn) note: some packets will arrive out of order, as they were part of a retransmission, and consequently arrive out of order, but carry the same fcn More... | |
| static void | mbuf_format (schc_mbuf_t **head, schc_fragmentation_t *conn) |
| remove the fragmentation headers and concat the data bits of the complete mbuf chain More... | |
| static uint8_t | get_header_length (schc_mbuf_t *mbuf, schc_fragmentation_t *conn) |
| Returns the number of bits the current header exists off. More... | |
| static unsigned int | mbuf_compute_mic (schc_fragmentation_t *conn) |
| Calculates the Message Integrity Check (MIC) over an unformatted mbuf chain containing the compressed, unfragmented packet which is the 8- 16- or 32- bit Cyclic Redundancy Check (CRC) More... | |
| static unsigned int | compute_mic (schc_fragmentation_t *conn) |
| Calculates the Message Integrity Check (MIC) which is the 8- 16- or 32- bit Cyclic Redundancy Check (CRC) More... | |
| static uint8_t | get_window_bit (uint8_t *fragment, schc_fragmentation_t *conn) |
| get the window bit More... | |
| static void | get_received_mic (uint8_t *fragment, uint8_t mic[], schc_fragmentation_t *conn) |
| get the MIC value More... | |
| static void | set_conn_frag_cnt (schc_fragmentation_t *conn, uint8_t frag) |
| set the fragmentation counter of the current connection which is the inverse of the fcn value More... | |
| static int8_t | init_tx_connection (schc_fragmentation_t *conn) |
| initializes a new tx transmission for a device: set the starting and ending point of the packet calculate the MIC over the complete SCHC packet More... | |
| void | schc_reset (schc_fragmentation_t *conn) |
| reset a connection More... | |
| static uint32_t | has_no_more_fragments (schc_fragmentation_t *conn) |
| check if a connection has more fragments to deliver More... | |
| static uint16_t | set_fragmentation_header (schc_fragmentation_t *conn, uint8_t *fragmentation_buffer) |
| set the fragmentation header More... | |
| static void | set_local_bitmap (schc_fragmentation_t *conn) |
| sets the local bitmap at the current fragment offset without encoding the bitmap More... | |
| static void | clear_bitmap (schc_fragmentation_t *conn) |
| clear the received and local bitmap More... | |
| static void | encode_bitmap (schc_fragmentation_t *conn) |
| encode the bitmap by removing all the right most contiguous BYTES in the non-encoded bitmap More... | |
| static void | decode_bitmap (schc_fragmentation_t *conn) |
| reconstruct an encoded bitmap More... | |
| static uint8_t | is_bitmap_full (schc_fragmentation_t *conn, uint8_t len) |
| loop over a bitmap to check if all bits are set to 1, starting from MAX_WIND_FCN More... | |
| static uint16_t | get_next_fragment_from_bitmap (schc_fragmentation_t *conn) |
| get the next fragment to retransmit according the fragmentation counter More... | |
| static void | discard_fragment (schc_fragmentation_t *conn) |
| discard a fragment More... | |
| static void | abort_connection (schc_fragmentation_t *conn) |
| abort an ongoing transmission because the inactivity timer has expired More... | |
| static void | set_retrans_timer (schc_fragmentation_t *conn) |
| sets the retransmission timer to re-enter the fragmentation loop and changes the retransmission_timer flag More... | |
| static void | set_dc_timer (schc_fragmentation_t *conn) |
| sets the duty cycle timer to re-enter the fragmentation loop More... | |
| static void | set_inactivity_timer (schc_fragmentation_t *conn) |
| sets the inactivity timer to re-enter the fragmentation loop and changes the retransmission_timer flag More... | |
| static uint8_t | empty_all_0 (schc_mbuf_t *mbuf, schc_fragmentation_t *conn) |
| checks if the fragment inside the mbuf is an all-0 empty More... | |
| static uint8_t | empty_all_1 (schc_mbuf_t *mbuf, schc_fragmentation_t *conn) |
| checks if the fragment inside the mbuf is an all-1 empty More... | |
| static uint8_t | send_fragment (schc_fragmentation_t *conn) |
| composes a packet based on the type of the packet and calls the callback function to transmit the packet More... | |
| static uint8_t | send_ack (schc_fragmentation_t *conn) |
| composes an ack based on the parameters found in the connection and calls the callback function to transmit the packet More... | |
| static uint8_t | send_empty (schc_fragmentation_t *conn) |
| composes an all-empty fragment based on the parameters found in the connection and calls the callback function to transmit the packet More... | |
| static uint8_t | send_tx_empty (schc_fragmentation_t *conn) |
| composes an all-empty fragment based on the parameters found in the connection and calls the callback function to transmit the packet More... | |
| schc_fragmentation_t * | schc_get_connection (uint32_t device_id) |
| find a connection based on a device id or open a new connection if there was no connection for this device yet More... | |
| static int8_t | mic_correct (schc_fragmentation_t *rx_conn) |
| sort the mbuf chain, find the MIC inside the last received fragment and compare with the calculated one More... | |
| static uint8_t | wait_end (schc_fragmentation_t *rx_conn, schc_mbuf_t *tail) |
| the function to call when the state machine is in WAIT END state More... | |
| int8_t | schc_reassemble (schc_fragmentation_t *rx_conn) |
| the receiver state machine More... | |
| int8_t | schc_fragmenter_init (schc_fragmentation_t *tx_conn, uint8_t(*send)(uint8_t *data, uint16_t length, uint32_t device_id), void(*end_rx)(schc_fragmentation_t *conn), void(*remove_timer_entry)(uint32_t device_id)) |
| Initializes the SCHC fragmenter. More... | |
| static void | tx_fragment_send (schc_fragmentation_t *tx_conn) |
| the function to call when the state machine is in SEND state More... | |
| static void | tx_fragment_resend (schc_fragmentation_t *tx_conn) |
| the function to call when the state machine is in RESEND state More... | |
| static void | no_missing_fragments_more_to_come (schc_fragmentation_t *tx_conn) |
| the function to call when the state machine has to continue transmission More... | |
| int8_t | schc_fragment (schc_fragmentation_t *tx_conn) |
| the sender state machine More... | |
| schc_fragmentation_t * | schc_input (uint8_t *data, uint16_t len, schc_fragmentation_t *tx_conn, uint32_t device_id) |
| This function should be called whenever a packet is received. More... | |
| void | schc_ack_input (uint8_t *data, uint16_t len, schc_fragmentation_t *tx_conn, uint32_t device_id) |
| This function should be called whenever an ack is received. More... | |
| schc_fragmentation_t * | schc_fragment_input (uint8_t *data, uint16_t len, uint32_t device_id) |
| This function should be called whenever a fragment is received an open connection is picked for the device out of a pool of connections to keep track of the packet. More... | |
Variables | |
| uint8_t | ATTEMPTS = 0 |
| struct schc_fragmentation_t | schc_rx_conns [SCHC_CONF_RX_CONNS] |
| static uint8_t | fragmentation_buffer [MAX_MTU_LENGTH] |
| static uint32_t | MBUF_PTR |
| static struct schc_mbuf_t | MBUF_POOL [SCHC_CONF_MBUF_POOL_LEN] |
| static uint8_t | buf_ptr = 0 |
| uint8_t | schc_buf [SCHC_BUFSIZE] = { 0 } |
|
static |
abort an ongoing transmission because the inactivity timer has expired
| conn | a pointer to the connection |
|
static |
clear the received and local bitmap
| conn | a pointer to the connection |
|
static |
Calculates the Message Integrity Check (MIC) which is the 8- 16- or 32- bit Cyclic Redundancy Check (CRC)
| conn | pointer to the connection |
|
static |
reconstruct an encoded bitmap
| conn | a pointer to the connection |
|
static |
discard a fragment
| conn | a pointer to the connection |
|
static |
checks if the fragment inside the mbuf is an all-0 empty
| mbuf | a pointer to the mbuf |
|
static |
checks if the fragment inside the mbuf is an all-1 empty
| mbuf | a pointer to the mbuf |
|
static |
encode the bitmap by removing all the right most contiguous BYTES in the non-encoded bitmap
| conn | a pointer to the connection |
|
static |
get a bitmap mask for a number of bits
| len | the number of bits to set |
|
static |
get the FCN value
| fragment | a pointer to the fragment to retrieve the FCN from |
|
static |
Returns the number of bits the current header exists off.
| mbuf | the mbuf to find th offset for |
|
static |
get the ALL-1 FCN value
| uint16_t get_mbuf_len | ( | schc_mbuf_t * | head | ) |
returns the total length of the mbuf
| head | the head of the list |
|
static |
returns the last chain in the mbuf linked list
| head | the head of the list |
|
static |
get the next fragment to retransmit according the fragmentation counter
| conn | a pointer to the connection |
|
static |
get the number of zero bits added to the end of the buffer
| byte | the byte to investigate |
|
static |
returns the last chain in the mbuf linked list
| head | the head of the list |
| mbuf | the mbuf to find the previous mbuf for |
|
static |
get the MIC value
| fragment | a pointer to the fragment to retrieve the MIC from |
| mic |
|
static |
get the window bit
| fragment | a pointer to the fragment to retrieve the window number from |
|
static |
check if a connection has more fragments to deliver
| conn | a pointer to the connection |
|
static |
initializes a new tx transmission for a device: set the starting and ending point of the packet calculate the MIC over the complete SCHC packet
| conn | a pointer to the connection to initialize |
|
static |
loop over a bitmap to check if all bits are set to 1, starting from MAX_WIND_FCN
| conn | a pointer to the connection |
| len | the length of the bitmap |
| void mbuf_clean | ( | schc_mbuf_t ** | head | ) |
delete all fragments chained in an mbuf
| head | the head of the list |
|
static |
Calculates the Message Integrity Check (MIC) over an unformatted mbuf chain containing the compressed, unfragmented packet which is the 8- 16- or 32- bit Cyclic Redundancy Check (CRC)
| head | the head of the list |
| void mbuf_copy | ( | schc_mbuf_t * | head, |
| uint8_t * | ptr | ||
| ) |
copy the byte alligned contents of the mbuf chain to the passed pointer
| head | the head of the list |
| ptr | the pointer to copy the contents to |
|
static |
delete a mbuf from the chain
| head | the head of the list |
| mbuf | the mbuf to delete |
|
static |
remove the fragmentation headers and concat the data bits of the complete mbuf chain
+-—+---------—+ +-—+---------—+ | FH | DATA | <— ... <— | FH | DATA | +-—+---------—+ +-—+---------—+
| head | double pointer to the head of the list |
|
static |
check if an mbuf with the same fragment number already exists and overwrite if so
| head | the head of the list |
| frag | the fragment number to overwrite |
| mbuf | the fragment to overwrite with |
|
static |
print the complete mbuf chain
| head | the head of the list |
|
static |
add an item to the end of the mbuf list if head is NULL, the first item of the list will be set
| head | the head of the list |
| data | a pointer to the data pointer |
| len | the length of the data |
|
static |
sort the complete mbuf chain based on fragment counter (fcn) note: some packets will arrive out of order, as they were part of a retransmission, and consequently arrive out of order, but carry the same fcn
| head | double pointer to the head of the list |
|
static |
sort the mbuf chain, find the MIC inside the last received fragment and compare with the calculated one
| rx_conn | a pointer to the rx connection structure |
|
static |
the function to call when the state machine has to continue transmission
| tx_conn | a pointer to the tx connection structure |
| void schc_ack_input | ( | uint8_t * | data, |
| uint16_t | len, | ||
| schc_fragmentation_t * | tx_conn, | ||
| uint32_t | device_id | ||
| ) |
This function should be called whenever an ack is received.
| data | a pointer to the received data |
| len | the length of the received packet |
| tx_conn | a pointer to the tx initialization structure |
| device_id | the device id from the rx source |
| int8_t schc_fragment | ( | schc_fragmentation_t * | tx_conn | ) |
the sender state machine
| tx_conn | a pointer to the tx connection structure |
| schc_fragmentation_t* schc_fragment_input | ( | uint8_t * | data, |
| uint16_t | len, | ||
| uint32_t | device_id | ||
| ) |
This function should be called whenever a fragment is received an open connection is picked for the device out of a pool of connections to keep track of the packet.
| data | a pointer to the data packet |
| len | the length of the received packet |
| device_id | the device id from the rx source |
| int8_t schc_fragmenter_init | ( | schc_fragmentation_t * | tx_conn, |
| uint8_t(*)(uint8_t *data, uint16_t length, uint32_t device_id) | send, | ||
| void(*)(schc_fragmentation_t *conn) | end_rx, | ||
| void(*)(uint32_t device_id) | remove_timer_entry | ||
| ) |
Initializes the SCHC fragmenter.
| tx_conn | a pointer to the tx initialization structure |
| send | a pointer to the send callback |
| end_rx | this function is called to indicate that the last rx timer has expired |
| remove_timer_entry | some scheduler implementations need a callback to remove a timer entry for a certain device |
| schc_fragmentation_t* schc_get_connection | ( | uint32_t | device_id | ) |
find a connection based on a device id or open a new connection if there was no connection for this device yet
| device_id | the id of the device to open a connection for |
| schc_fragmentation_t* schc_input | ( | uint8_t * | data, |
| uint16_t | len, | ||
| schc_fragmentation_t * | tx_conn, | ||
| uint32_t | device_id | ||
| ) |
This function should be called whenever a packet is received.
| data | a pointer to the received data |
| len | the length of the received packet |
| tx_conn | a pointer to the tx initialization structure |
| device_id | the device id from the rx source |
| int8_t schc_reassemble | ( | schc_fragmentation_t * | rx_conn | ) |
the receiver state machine
| conn | a pointer to the connection |
| void schc_reset | ( | schc_fragmentation_t * | conn | ) |
reset a connection
| conn | a pointer to the connection to reset |
|
static |
composes an ack based on the parameters found in the connection and calls the callback function to transmit the packet
| conn | a pointer to the connection |
@ret 0 the packet was not sent 1 the packet was transmitted
|
static |
composes an all-empty fragment based on the parameters found in the connection and calls the callback function to transmit the packet
| conn | a pointer to the connection |
@ret 0 the packet was not sent 1 the packet was transmitted
|
static |
composes a packet based on the type of the packet and calls the callback function to transmit the packet
| conn | a pointer to the connection |
@ret 0 the packet was not sent 1 the packet was transmitted
|
static |
composes an all-empty fragment based on the parameters found in the connection and calls the callback function to transmit the packet
| conn | a pointer to the connection |
@ret 0 the packet was not sent 1 the packet was transmitted
|
static |
set the fragmentation counter of the current connection which is the inverse of the fcn value
| conn | a pointer to the connection |
| frag | the fcn value |
|
static |
sets the duty cycle timer to re-enter the fragmentation loop
| conn | a pointer to the connection |
|
static |
set the fragmentation header
| conn | a pointer to the connection |
| buffer | a pointer to the buffer to set the header |
|
static |
sets the inactivity timer to re-enter the fragmentation loop and changes the retransmission_timer flag
| conn | a pointer to the connection |
|
static |
sets the local bitmap at the current fragment offset without encoding the bitmap
| conn | a pointer to the connection |
|
static |
sets the retransmission timer to re-enter the fragmentation loop and changes the retransmission_timer flag
| conn | a pointer to the connection |
|
static |
the function to call when the state machine is in RESEND state
| tx_conn | a pointer to the tx connection structure |
|
static |
the function to call when the state machine is in SEND state
| tx_conn | a pointer to the tx connection structure |
|
static |
the function to call when the state machine is in WAIT END state
| rx_conn | a pointer to the rx connection structure |
| uint8_t ATTEMPTS = 0 |
|
static |
|
static |
|
static |
|
static |
| uint8_t schc_buf[SCHC_BUFSIZE] = { 0 } |
| struct schc_fragmentation_t schc_rx_conns[SCHC_CONF_RX_CONNS] |
1.8.17