Skip to content

Commit f94b2ab

Browse files
author
Jarkko Paso
committed
FHSS: FHSS to use synch info callback
1 parent 6830fd3 commit f94b2ab

File tree

9 files changed

+43
-25
lines changed

9 files changed

+43
-25
lines changed

nanostack/fhss_api.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
8383
* @param is_broadcast_addr Destination address type of packet (true if broadcast address).
8484
* @param destination_address Destination MAC address.
8585
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
86-
* @param synch_info Pointer to where FHSS synchronization info is written (if synch frame).
8786
* @param frame_length MSDU length of the frame.
8887
* @param phy_header_length PHY header length.
8988
* @param phy_tail_length PHY tail length.
@@ -93,7 +92,7 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
9392
* @return -3 Broadcast packet on Unicast channel (not allowed), push packet back to queue.
9493
* @return -4 Synchronization info missing.
9594
*/
96-
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);
95+
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);
9796

9897
/**
9998
* @brief Check TX permission.

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,13 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
179179
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
180180
dev_driver_tx_buffer_s *tx_buf = &rf_mac_setup->dev_driver_tx_buffer;
181181
synch_info = tx_buf->buf + rf_mac_setup->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
182+
//TODO: Add proper frame type when they are defined
183+
rf_mac_setup->fhss_api->write_synch_info(rf_mac_setup->fhss_api, synch_info, FHSS_PLAIN_SYNCH_INFO, 0, 0);
182184
}
183185
// Change to destination channel and write synchronization info to Beacon frames here
184186
int tx_handle_retval = rf_mac_setup->fhss_api->tx_handle(rf_mac_setup->fhss_api, !mac_is_ack_request_set(active_buf),
185187
active_buf->DstAddr, mac_convert_frame_type_to_fhss(active_buf->fcf_dsn.frametype),
186-
synch_info, active_buf->mac_payload_length, rf_mac_setup->dev_driver->phy_driver->phy_header_length,
188+
active_buf->mac_payload_length, rf_mac_setup->dev_driver->phy_driver->phy_header_length,
187189
rf_mac_setup->dev_driver->phy_driver->phy_tail_length);
188190
// When FHSS TX handle returns -1, transmission of the packet is currently not allowed -> restart CCA timer
189191
if (tx_handle_retval == -1) {

source/Service_Libs/fhss/fhss_configuration_interface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
5151
this->synch_state_set = &fhss_synch_state_set_cb;
5252
this->read_timestamp = &fhss_read_timestamp_cb;
5353
this->get_retry_period = &fhss_get_retry_period_cb;
54+
this->write_synch_info = &fhss_write_synch_info_cb;
5455
this->init_callbacks = &fhss_init_callbacks_cb;
5556
return this;
5657
}

source/Service_Libs/fhss/fhss_mac_interface.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
5656
return is_broadcast_addr;
5757
}
5858

59-
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)
59+
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)
6060
{
6161
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
6262
if (!fhss_structure) {
@@ -71,12 +71,7 @@ int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *de
7171
}
7272
}
7373
}
74-
if (frame_type == FHSS_SYNCH_FRAME) {
75-
if (!synch_info) {
76-
return -4;
77-
}
78-
fhss_beacon_build(fhss_structure, synch_info);
79-
} else if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
74+
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
8075
return -1;
8176
}
8277
// If sending Beacon request on parents Unicast channel
@@ -297,6 +292,25 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
297292
return retry_period;
298293
}
299294

295+
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)
296+
{
297+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
298+
(void) frame_type_id;
299+
(void) tx_time;
300+
if (!fhss_structure) {
301+
return -1;
302+
}
303+
if (info_type == FHSS_PLAIN_SYNCH_INFO) {
304+
if (!info_ptr) {
305+
return -1;
306+
}
307+
fhss_beacon_build(fhss_structure, info_ptr);
308+
return FHSS_SYNCH_INFO_LENGTH;
309+
}
310+
return -1;
311+
}
312+
313+
300314
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
301315
{
302316
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);

source/Service_Libs/fhss/fhss_mac_interface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
2222
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
23-
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);
23+
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);
2424
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);
2525
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);
2626
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
2727
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
2828
void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
2929
uint32_t fhss_read_timestamp_cb(const fhss_api_t *api);
3030
uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
31+
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);
3132
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks);
3233

3334
#endif /* FHSS_MAC_INTERFACE_H_ */

test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool test_ns_fhss_create()
8383
if (fhss_mac_interface_stub.int8_value != 7) {
8484
return false;
8585
}
86-
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0);
86+
api->tx_handle(api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0);
8787
if (fhss_mac_interface_stub.int8_value != 8) {
8888
return false;
8989
}

test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,41 +80,36 @@ bool test_fhss_use_broadcast_queue_cb()
8080
bool test_fhss_tx_handle_cb()
8181
{
8282
fhss_api_t fhss_api;
83-
uint8_t synch_info[FHSS_SYNCH_INFO_LENGTH];
8483

8584
// By setting bool value false, fhss_struct can not be found
8685
fhss_stub.bool_value = false;
87-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0) != -2) {
86+
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -2) {
8887
return false;
8988
}
9089
// By setting bool value true, fhss_struct can be found
9190
fhss_stub.bool_value = true;
9291
// Broadcast data on unicast channel should return -3
9392
fhss_channel_stub.channel_bool_value = false;
94-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, NULL, 0, 0, 0) != -3) {
95-
return false;
96-
}
97-
// Synch frame without synch info should return -4
98-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, NULL, 0, 0, 0) != -4) {
93+
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
9994
return false;
10095
}
10196
// Test sending of Beacon
102-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, synch_info, 0, 0, 0) != 0) {
97+
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
10398
return false;
10499
}
105100
// When TX is not allowed, should return -1 for data frame
106101
fhss_stub.tx_allowed_bool_value = false;
107-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, synch_info, 0, 0, 0) != -1) {
102+
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
108103
return false;
109104
}
110105
// When TX is allowed, should return 0 for data frame
111106
fhss_stub.tx_allowed_bool_value = true;
112-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, synch_info, 0, 0, 0) != 0) {
107+
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
113108
return false;
114109
}
115110
// Test changing to parent channel to send synch request
116111
fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
117-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, synch_info, 0, 0, 0) != 0) {
112+
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
118113
return false;
119114
}
120115
return true;

test/nanostack/unittest/stub/fhss_mac_interface_stub.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
3333
return fhss_mac_interface_stub.queue_bool_value;
3434
}
3535

36-
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)
36+
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)
3737
{
3838
fhss_mac_interface_stub.int8_value++;
3939
return fhss_mac_interface_stub.handle_value;
@@ -79,6 +79,12 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad
7979
{
8080
return 0;
8181
}
82+
83+
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)
84+
{
85+
return 0;
86+
}
87+
8288
int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks)
8389
{
8490

test/nanostack/unittest/stub/fhss_mac_interface_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern fhss_mac_interface_stub_def fhss_mac_interface_stub;
3434

3535
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
3636
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
37-
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);
37+
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);
3838
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);
3939
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);
4040
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);

0 commit comments

Comments
 (0)