Skip to content

Commit

Permalink
Merge pull request ARMmbed#1532 from ARMmbed/IOTTHD-2049
Browse files Browse the repository at this point in the history
Iotthd 2049
  • Loading branch information
Jarkko Paso authored Jan 17, 2018
2 parents b741f98 + 55861f3 commit b643622
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 31 deletions.
37 changes: 35 additions & 2 deletions nanostack/fhss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ typedef struct fhss_callback fhss_callback_t;
#define FHSS_SYNCH_REQUEST_FRAME 1 /**< FHSS synchronization request frame */
#define FHSS_DATA_FRAME 2 /**< FHSS data frame */

/**
* @brief FHSS information element types.
*/
#define FHSS_UTT_IE 0 /**< UTT-IE */
#define FHSS_BT_IE 1 /**< BT-IE */
#define FHSS_US_IE 2 /**< US-IE */
#define FHSS_BS_IE 3 /**< BS-IE */
#define FHSS_PLAIN_SYNCH_INFO 4 /**< Plain synchronization information */

/**
* @brief FHSS synchronization info length.
*/
Expand Down Expand Up @@ -74,7 +83,6 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
* @param is_broadcast_addr Destination address type of packet (true if broadcast address).
* @param destination_address Destination MAC address.
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
* @param synch_info Pointer to where FHSS synchronization info is written (if synch frame).
* @param frame_length MSDU length of the frame.
* @param phy_header_length PHY header length.
* @param phy_tail_length PHY tail length.
Expand All @@ -84,7 +92,7 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
* @return -3 Broadcast packet on Unicast channel (not allowed), push packet back to queue.
* @return -4 Synchronization info missing.
*/
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);

/**
* @brief Check TX permission.
Expand Down Expand Up @@ -152,6 +160,17 @@ typedef uint32_t fhss_read_timestamp(const fhss_api_t *api);
*/
typedef uint16_t fhss_get_retry_period(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);

/**
* @brief Write synchronization info to given pointer.
* @param api FHSS instance.
* @param info_ptr Pointer to written data.
* @param info_type Type of the written info (UTT-IE, BT-IE, US-IE, BS-IE).
* @param frame_type_id Frame type of packet which will be written in info element.
* @param tx_time TX time must be referenced to the first symbol following the SFD of the transmitted frame.
* @return -1 on fail, write length otherwise.
*/
typedef int16_t fhss_write_synch_info(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time);

/**
* @brief Initialize MAC functions.
* @param api FHSS instance.
Expand All @@ -177,6 +196,7 @@ struct fhss_api {
fhss_synch_state_set *synch_state_set; /**< Change synchronization state. */
fhss_read_timestamp *read_timestamp; /**< Read timestamp. */
fhss_get_retry_period *get_retry_period; /**< Get retransmission period. */
fhss_write_synch_info *write_synch_info; /**< Write synchronization info to TX frame*/
fhss_init_callbacks *init_callbacks; /**< Initialize MAC functions. */
};

Expand Down Expand Up @@ -256,6 +276,18 @@ typedef int mac_broadcast_notify(const fhss_api_t *fhss_api, uint32_t broadcast_
*/
typedef int mac_read_coordinator_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address);

/**
* @brief Read synchronization info for a specific peer.
* @param fhss_api FHSS instance.
* @param info_ptr Pointer to info data.
* @param mac_address MAC address pointer.
* @param info_type Type of the read info (UTT-IE, BT-IE, US-IE, BS-IE).
* @param rx_timestamp Time of reception of the element.
* @return >=0 Length of the info.
* @return -1 Fail.
*/
typedef int mac_read_synch_info(const fhss_api_t *fhss_api, uint8_t *info_ptr, uint8_t *mac_address, int info_type, uint32_t rx_timestamp);

/**
* \brief Struct fhss_callback defines functions that software MAC needs to implement.
* Function pointers are passed to FHSS using fhss_init_callbacks function.
Expand All @@ -270,6 +302,7 @@ struct fhss_callback {
mac_tx_poll *tx_poll; /**< Poll TX queue. */
mac_broadcast_notify *broadcast_notify; /**< Broadcast channel notification from FHSS. */
mac_read_coordinator_mac_address *read_coord_mac_address; /**< Read coordinator MAC address. */
mac_read_synch_info *read_synch_info; /**< Read information element for a specific MAC address. */
};

#ifdef __cplusplus
Expand Down
12 changes: 9 additions & 3 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ typedef struct fhss_configuration
*/
typedef struct fhss_timer
{
/** Start timeout (1us) */
/** Start timeout (1us). Timer must support multiple simultaneous timeouts */
int (*fhss_timer_start)(uint32_t, void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Stop timeout */
int (*fhss_timer_stop)(const fhss_api_t *fhss_api);
int (*fhss_timer_stop)(void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Get remaining time of started timeout*/
uint32_t (*fhss_get_remaining_slots)(const fhss_api_t *fhss_api);
uint32_t (*fhss_get_remaining_slots)(void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Get timestamp since initialization of driver. Overflow of 32-bit counter is allowed (1us) */
uint32_t (*fhss_get_timestamp)(const fhss_api_t *fhss_api);
Expand All @@ -103,6 +103,12 @@ typedef struct fhss_synch_configuration

/** Number of superframes. */
uint8_t fhss_number_of_superframes;

/** Broadcast interval. Interval between started broadcast channels. (milliseconds) */
uint32_t fhss_broadcast_interval;

/** Broadcast dwell time. (milliseconds) */
uint8_t fhss_bc_dwell_interval;
} fhss_synch_configuration_t;


Expand Down
4 changes: 3 additions & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,13 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
dev_driver_tx_buffer_s *tx_buf = &rf_mac_setup->dev_driver_tx_buffer;
synch_info = tx_buf->buf + rf_mac_setup->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
//TODO: Add proper frame type when they are defined
rf_mac_setup->fhss_api->write_synch_info(rf_mac_setup->fhss_api, synch_info, FHSS_PLAIN_SYNCH_INFO, 0, 0);
}
// Change to destination channel and write synchronization info to Beacon frames here
int tx_handle_retval = rf_mac_setup->fhss_api->tx_handle(rf_mac_setup->fhss_api, !mac_is_ack_request_set(active_buf),
active_buf->DstAddr, mac_convert_frame_type_to_fhss(active_buf->fcf_dsn.frametype),
synch_info, active_buf->mac_payload_length, rf_mac_setup->dev_driver->phy_driver->phy_header_length,
active_buf->mac_payload_length, rf_mac_setup->dev_driver->phy_driver->phy_header_length,
rf_mac_setup->dev_driver->phy_driver->phy_tail_length);
// When FHSS TX handle returns -1, transmission of the packet is currently not allowed -> restart CCA timer
if (tx_handle_retval == -1) {
Expand Down
6 changes: 3 additions & 3 deletions source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor, bool re
static int fhss_reset(fhss_structure_t *fhss_structure)
{
if (fhss_structure) {
fhss_structure->platform_functions.fhss_timer_stop(fhss_structure->fhss_api);
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
fhss_struct->synch_panid = 0xffff;
fhss_beacon_periodic_stop(fhss_structure);
fhss_struct->current_superframe = 0;
Expand Down Expand Up @@ -374,7 +374,7 @@ void fhss_start_timer(fhss_structure_t *fhss_structure, uint32_t time, void (*ca

uint32_t fhss_get_remaining_time_to_next_superframe(const fhss_structure_t *fhss_structure)
{
const uint32_t slots = fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_structure->fhss_api);
const uint32_t slots = fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_superframe_handler, fhss_structure->fhss_api);
const uint32_t time = slots * fhss_structure->platform_functions.fhss_resolution_divider;
return time;
}
Expand Down Expand Up @@ -657,7 +657,7 @@ int fhss_sync_with_beacon(fhss_structure_t *fhss_structure,
fhss_structure->uc_channel_index -= (fhss_structure->number_of_channels - payload->number_of_broadcast_channels);
}

fhss_structure->platform_functions.fhss_timer_stop(fhss_structure->fhss_api);
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
// start timer to elapse at approximately same time as the parent will.
const int32_t time_to_next_superframe = payload->remaining_slots;
remaining_time_own = fhss_get_remaining_time_to_next_superframe(fhss_structure);
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_configuration_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
this->synch_state_set = &fhss_synch_state_set_cb;
this->read_timestamp = &fhss_read_timestamp_cb;
this->get_retry_period = &fhss_get_retry_period_cb;
this->write_synch_info = &fhss_write_synch_info_cb;
this->init_callbacks = &fhss_init_callbacks_cb;
return this;
}
Expand Down
28 changes: 21 additions & 7 deletions source/Service_Libs/fhss/fhss_mac_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
return is_broadcast_addr;
}

int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
Expand All @@ -71,12 +71,7 @@ int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *de
}
}
}
if (frame_type == FHSS_SYNCH_FRAME) {
if (!synch_info) {
return -4;
}
fhss_beacon_build(fhss_structure, synch_info);
} else if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
return -1;
}
// If sending Beacon request on parents Unicast channel
Expand Down Expand Up @@ -297,6 +292,25 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
return retry_period;
}

int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
(void) frame_type_id;
(void) tx_time;
if (!fhss_structure) {
return -1;
}
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
if (!info_ptr) {
return -1;
}
fhss_beacon_build(fhss_structure, info_ptr);
return FHSS_SYNCH_INFO_LENGTH;
}
return -1;
}


int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
Expand Down
3 changes: 2 additions & 1 deletion source/Service_Libs/fhss/fhss_mac_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
bool fhss_check_tx_conditions_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api);
uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time);
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks);

#endif /* FHSS_MAC_INTERFACE_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool test_ns_fhss_create()
if (fhss_mac_interface_stub.int8_value != 7) {
return false;
}
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0);
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0);
if (fhss_mac_interface_stub.int8_value != 8) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,36 @@ bool test_fhss_use_broadcast_queue_cb()
bool test_fhss_tx_handle_cb()
{
fhss_api_t fhss_api;
uint8_t synch_info[FHSS_SYNCH_INFO_LENGTH];

// By setting bool value false, fhss_struct can not be found
fhss_stub.bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0) != -2) {
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -2) {
return false;
}
// By setting bool value true, fhss_struct can be found
fhss_stub.bool_value = true;
// Broadcast data on unicast channel should return -3
fhss_channel_stub.channel_bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0) != -3) {
return false;
}
// Synch frame without synch info should return -4
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, NULL, 0, 0, 0) != -4) {
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
return false;
}
// Test sending of Beacon
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, synch_info, 0, 0, 0) != 0) {
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
return false;
}
// When TX is not allowed, should return -1 for data frame
fhss_stub.tx_allowed_bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, synch_info, 0, 0, 0) != -1) {
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
return false;
}
// When TX is allowed, should return 0 for data frame
fhss_stub.tx_allowed_bool_value = true;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, synch_info, 0, 0, 0) != 0) {
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
return false;
}
// Test changing to parent channel to send synch request
fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, synch_info, 0, 0, 0) != 0) {
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
return false;
}
return true;
Expand Down
1 change: 1 addition & 0 deletions test/nanostack/unittest/stub/fhss_config_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
fhss_config_stub.fhss_api_ptr.synch_state_set = &fhss_synch_state_set_cb;
fhss_config_stub.fhss_api_ptr.read_timestamp = &fhss_read_timestamp_cb;
fhss_config_stub.fhss_api_ptr.get_retry_period = &fhss_get_retry_period_cb;
fhss_config_stub.fhss_api_ptr.write_synch_info = &fhss_write_synch_info_cb;
fhss_config_stub.fhss_api_ptr.init_callbacks = &fhss_init_callbacks_cb;
return &fhss_config_stub.fhss_api_ptr;
}
8 changes: 7 additions & 1 deletion test/nanostack/unittest/stub/fhss_mac_interface_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
return fhss_mac_interface_stub.queue_bool_value;
}

int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_mac_interface_stub.int8_value++;
return fhss_mac_interface_stub.handle_value;
Expand Down Expand Up @@ -79,6 +79,12 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
{
return 0;
}

int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time)
{
return 0;
}

int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
{

Expand Down
3 changes: 2 additions & 1 deletion test/nanostack/unittest/stub/fhss_mac_interface_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ extern fhss_mac_interface_stub_def fhss_mac_interface_stub;

bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
bool fhss_check_tx_conditions_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api);
uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time);
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks);

#ifdef __cplusplus
Expand Down

0 comments on commit b643622

Please sign in to comment.