Skip to content

Commit 51429c9

Browse files
author
Jarkko Paso
authored
FHSS WS: api function to set TX allowance level (ARMmbed#2612)
* FHSS WS: api function to set TX allowance level * Set both TX allowance levels with single function call
1 parent 01b1188 commit 51429c9

File tree

8 files changed

+91
-12
lines changed

8 files changed

+91
-12
lines changed

nanostack/fhss_ws_extension.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ extern int ns_fhss_set_neighbor_info_fp(const fhss_api_t *fhss_api, fhss_get_nei
118118
*/
119119
extern int ns_fhss_ws_set_hop_count(const fhss_api_t *fhss_api, const uint8_t hop_count);
120120

121+
/**
122+
* @brief WS TX allowance levels.
123+
*/
124+
typedef enum {
125+
/** Allow transmitting only on TX slots. */
126+
WS_TX_SLOT,
127+
/** Allow transmitting only on TX and RX slots. */
128+
WS_TX_AND_RX_SLOT,
129+
/** Allow transmitting always. Also unicast on broadcast channel. */
130+
WS_TX_ALWAYS
131+
} fhss_ws_tx_allow_level;
132+
133+
/**
134+
* @brief Set node unicast TX allowance level. Allows device to use the unicast and broadcast channel for unicast transmission as described by fhss_ws_tx_allow_level.
135+
* @param fhss_api FHSS instance.
136+
* @param global_level Level of TX allowance in normal mode.
137+
* @param ef_level Level of TX allowance in expedited forwarding mode.
138+
* @return 0 on success, -1 on fail.
139+
*/
140+
extern int ns_fhss_ws_set_tx_allowance_level(const fhss_api_t *fhss_api, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level);
141+
121142
#ifdef __cplusplus
122143
}
123144
#endif

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
679679
return -1;
680680
}
681681
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
682+
// Allow transmitting unicast frames only on TX slots in normal and expedited forwarding mode
683+
ns_fhss_ws_set_tx_allowance_level(fhss_api, WS_TX_SLOT, WS_TX_SLOT);
682684
} else {
683685
// Read defaults from the configuration to help FHSS testing
684686
const fhss_ws_configuration_t *fhss_configuration_copy = ns_fhss_ws_configuration_get(fhss_api);
@@ -2652,6 +2654,13 @@ static void ws_set_fhss_hop(protocol_interface_info_entry_t *cur)
26522654
// Calculate own hop count. This method gets inaccurate when hop count increases.
26532655
uint8_t own_hop = (own_rank - rank_inc) / rank_inc;
26542656
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, own_hop);
2657+
if (own_hop == 1) {
2658+
// Allow transmitting unicast frames only on TX slots in normal mode and always in expedited forwarding mode for first hop
2659+
ns_fhss_ws_set_tx_allowance_level(cur->ws_info->fhss_api, WS_TX_SLOT, WS_TX_ALWAYS);
2660+
} else {
2661+
// Allow transmitting unicast frames only on TX slots in normal and expedited forwarding mode for other hops
2662+
ns_fhss_ws_set_tx_allowance_level(cur->ws_info->fhss_api, WS_TX_SLOT, WS_TX_SLOT);
2663+
}
26552664
tr_debug("own hop: %u, own rank: %u, rank inc: %u", own_hop, own_rank, rank_inc);
26562665
}
26572666

source/Service_Libs/fhss/fhss_configuration_interface.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ int ns_fhss_ws_set_hop_count(const fhss_api_t *fhss_api, const uint8_t hop_count
140140
return fhss_ws_set_hop_count(fhss_structure, hop_count);
141141
}
142142

143+
int ns_fhss_ws_set_tx_allowance_level(const fhss_api_t *fhss_api, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level)
144+
{
145+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
146+
if (!fhss_structure || !fhss_structure->ws) {
147+
return -1;
148+
}
149+
return fhss_ws_set_tx_allowance_level(fhss_structure, global_level, ef_level);
150+
}
151+
143152
int ns_fhss_statistics_start(const fhss_api_t *fhss_api, fhss_statistics_t *fhss_statistics)
144153
{
145154
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
169169
fhss_ws_set_hop_count(fhss_struct, 0xff);
170170
fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel;
171171
fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL;
172+
// By default, allow transmitting unicast data only on TX slots.
173+
fhss_struct->ws->tx_level = WS_TX_SLOT;
174+
// By default, allow always transmitting unicast data in expedited forwarding mode.
175+
fhss_struct->ws->ef_tx_level = WS_TX_ALWAYS;
172176
ns_list_init(&fhss_struct->fhss_failed_tx_list);
173177
return fhss_struct;
174178
}
@@ -780,26 +784,26 @@ static bool fhss_ws_check_tx_time(fhss_structure_t *fhss_structure, uint16_t tx_
780784

781785
static bool fhss_allow_transmitting_on_rx_slot(fhss_structure_t *fhss_structure)
782786
{
783-
// This is allowed only for 1st hop devices in expedited forwarding mode
784-
if (!fhss_structure->ws->expedited_forwarding_enabled_us) {
785-
return false;
787+
if (fhss_structure->ws->tx_level >= WS_TX_AND_RX_SLOT) {
788+
return true;
786789
}
787-
if (fhss_structure->own_hop != 1) {
788-
return false;
790+
// This is allowed only for devices in expedited forwarding mode
791+
if (fhss_structure->ws->expedited_forwarding_enabled_us && (fhss_structure->ws->ef_tx_level >= WS_TX_AND_RX_SLOT)) {
792+
return true;
789793
}
790-
return true;
794+
return false;
791795
}
792796

793797
static bool fhss_allow_unicast_on_broadcast_channel(fhss_structure_t *fhss_structure)
794798
{
795-
// This is allowed only for 1st hop devices in expedited forwarding mode
796-
if (!fhss_structure->ws->expedited_forwarding_enabled_us) {
797-
return false;
799+
if (fhss_structure->ws->tx_level >= WS_TX_ALWAYS) {
800+
return true;
798801
}
799-
if (fhss_structure->own_hop != 1) {
800-
return false;
802+
// This is allowed only for devices in expedited forwarding mode
803+
if (fhss_structure->ws->expedited_forwarding_enabled_us && (fhss_structure->ws->ef_tx_level >= WS_TX_ALWAYS)) {
804+
return true;
801805
}
802-
return true;
806+
return false;
803807
}
804808

805809
static bool fhss_ws_check_tx_conditions_callback(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)
@@ -1234,4 +1238,11 @@ int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_co
12341238
return 0;
12351239
}
12361240

1241+
int fhss_ws_set_tx_allowance_level(fhss_structure_t *fhss_structure, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level)
1242+
{
1243+
fhss_structure->ws->tx_level = global_level;
1244+
fhss_structure->ws->ef_tx_level = ef_level;
1245+
return 0;
1246+
}
1247+
12371248
#endif // HAVE_WS

source/Service_Libs/fhss/fhss_ws.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct fhss_ws {
5454
bool unicast_timer_running;
5555
bool broadcast_timer_running;
5656
bool is_on_bc_channel;
57+
fhss_ws_tx_allow_level tx_level;
58+
fhss_ws_tx_allow_level ef_tx_level;
5759
struct fhss_ws_configuration fhss_configuration;
5860
const struct broadcast_timing_info *parent_bc_info;
5961
fhss_get_neighbor_info *get_neighbor_info;
@@ -65,6 +67,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
6567
int fhss_ws_remove_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8]);
6668
int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_configuration_t *fhss_configuration);
6769
int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_count);
70+
int fhss_ws_set_tx_allowance_level(fhss_structure_t *fhss_structure, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level);
6871
void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);
6972

7073
#endif /*FHSS_WS_H_*/

source/Service_Libs/fhss/fhss_ws_empty_functions.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,14 @@ int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_co
8080
return -1;
8181
}
8282

83+
int fhss_ws_set_tx_allowance_level(fhss_structure_t *fhss_structure, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level)
84+
{
85+
(void) fhss_structure;
86+
(void) global_level;
87+
(void) ef_level;
88+
89+
return -1;
90+
}
91+
8392
#endif // HAVE_WS
8493

test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ static fhss_api_t *test_generate_fhss_api(void)
159159
fhss_common_stub.fhss_struct.fhss_state = FHSS_UNSYNCHRONIZED;
160160
fhss_common_stub.fhss_struct.own_hop = 0xff;
161161
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
162+
fhss_common_stub.fhss_struct.ws->tx_level = WS_TX_SLOT;
163+
fhss_common_stub.fhss_struct.ws->ef_tx_level = WS_TX_ALWAYS;
162164
fhss_common_stub.fhss_struct.callbacks.change_channel = &mac_set_channel;
163165
fhss_common_stub.fhss_struct.callbacks.read_mac_address = &mac_read_64bit_mac_address;
164166
fhss_common_stub.fhss_struct.callbacks.read_tx_queue_size = &mac_read_tx_queue_sizes;
@@ -354,6 +356,7 @@ bool test_fhss_ws_tx_handle_callback()
354356
}
355357
// Test TX allowed on RX slot for 1st hop in expedited forwarding mode
356358
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
359+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_AND_RX_SLOT);
357360
fhss_common_stub.fhss_struct.own_hop = 1;
358361
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
359362
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
@@ -378,6 +381,7 @@ bool test_fhss_ws_tx_handle_callback()
378381
}
379382
// Test TX allowed on broadcast channel for 1st hop in expedited forwarding mode
380383
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
384+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_ALWAYS);
381385
fhss_common_stub.fhss_struct.own_hop = 1;
382386
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
383387
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
@@ -390,6 +394,7 @@ bool test_fhss_ws_tx_handle_callback()
390394
}
391395
// Test TX not allowed on broadcast channel for 2nd hop in expedited forwarding mode
392396
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
397+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_SLOT);
393398
fhss_common_stub.fhss_struct.own_hop = 2;
394399
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
395400
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -3) {
@@ -487,6 +492,7 @@ bool test_fhss_ws_check_tx_conditions_callback()
487492
}
488493
// Test TX allowed on RX slot for 1st hop in expedited forwarding mode
489494
fhss_common_stub.fhss_struct.own_hop = 1;
495+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_AND_RX_SLOT);
490496
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
491497
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
492498
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 255;
@@ -504,6 +510,7 @@ bool test_fhss_ws_check_tx_conditions_callback()
504510
}
505511
// Test TX not allowed on RX slot for 2nd hop in expedited forwarding mode
506512
fhss_common_stub.fhss_struct.own_hop = 2;
513+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_SLOT);
507514
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
508515
fhss_platform_stub.remaining_slots_value = 700000;
509516
if (fhss_common_stub.fhss_struct.fhss_api->check_tx_conditions(api, DEFAULT_IS_BC_DEST, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
@@ -526,6 +533,7 @@ bool test_fhss_ws_check_tx_conditions_callback()
526533
}
527534
// Test TX allowed on broadcast channel for 1st hop in expedited forwarding mode
528535
fhss_common_stub.fhss_struct.own_hop = 1;
536+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_ALWAYS);
529537
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = true;
530538
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
531539
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
@@ -538,12 +546,14 @@ bool test_fhss_ws_check_tx_conditions_callback()
538546
}
539547
// Test TX not allowed on broadcast channel for 2nd hop in expedited forwarding mode
540548
fhss_common_stub.fhss_struct.own_hop = 2;
549+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_SLOT);
541550
if (fhss_common_stub.fhss_struct.fhss_api->check_tx_conditions(api, DEFAULT_IS_BC_DEST, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
542551
printf("Fail: TX conditions, 2nd hop, EF enabled on BC\r\n");
543552
return false;
544553
}
545554
// Test TX not allowed on broadcast channel for 1st hop when expedited forwarding mode disabled
546555
fhss_common_stub.fhss_struct.own_hop = 1;
556+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_ALWAYS);
547557
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 0;
548558
if (fhss_common_stub.fhss_struct.fhss_api->check_tx_conditions(api, DEFAULT_IS_BC_DEST, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
549559
printf("Fail: TX conditions, 1st hop, EF disabled on BC\r\n");
@@ -940,6 +950,7 @@ bool test_fhss_ws_get_retry_period_callback()
940950
}
941951
// Test retrying allowed on RX slot for 1st hop in expedited forwarding mode
942952
fhss_common_stub.fhss_struct.own_hop = 1;
953+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_ALWAYS);
943954
fhss_common_stub.fhss_struct.ws->expedited_forwarding_enabled_us = 1000000;
944955
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1020;
945956
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 255;
@@ -955,6 +966,7 @@ bool test_fhss_ws_get_retry_period_callback()
955966
}
956967
// Test retrying not allowed on RX slot for 2nd hop in expedited forwarding mode
957968
fhss_common_stub.fhss_struct.own_hop = 2;
969+
fhss_ws_set_tx_allowance_level(&fhss_common_stub.fhss_struct, WS_TX_SLOT, WS_TX_SLOT);
958970
fhss_platform_stub.remaining_slots_value = 700000;
959971
retry_period = fhss_common_stub.fhss_struct.fhss_api->get_retry_period(api, NULL, 0);
960972
if (retry_period != 70000) {

test/nanostack/unittest/stub/fhss_ws_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_co
5858
{
5959
return 0;
6060
}
61+
62+
int fhss_ws_set_tx_allowance_level(fhss_structure_t *fhss_structure, const fhss_ws_tx_allow_level global_level, const fhss_ws_tx_allow_level ef_level)
63+
{
64+
return 0;
65+
}

0 commit comments

Comments
 (0)