Skip to content

Commit 1283077

Browse files
author
Arto Kinnunen
authored
Test API to adjust 6LoWPAN fragmentation MTU size (ARMmbed#2398)
Add test API to allow testing of 6LoWPAN fragmentation.
1 parent e787874 commit 1283077

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

nanostack/net_ws_test.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ int ws_test_gtk_time_settings_set(
167167
*/
168168
int ws_test_next_gtk_set(int8_t interface_id, uint8_t *gtk[4]);
169169

170+
/**
171+
* Sets 6LoWPAN fragmentation MTU size to test fragmentation
172+
*
173+
* \param interface_id Network interface ID.
174+
* \param mtu_size Size of 6LoWPAN MTU when fragmentation occurs.
175+
*
176+
* \return 0 Success
177+
* \return <0 Failure
178+
*/
179+
int ws_test_6lowpan_fragmentation_mtu_size_set(int8_t interface_id, uint16_t mtu_size);
180+
170181
#ifdef __cplusplus
171182
}
172183
#endif

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
static const uint8_t mac_helper_default_key_source[8] = {0xff, 0, 0, 0, 0, 0, 0, 0};
3333

34+
uint16_t test_6lowpan_fragmentation_mtu_size_override = 0;
35+
3436
static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode);
3537
static uint8_t mac_helper_security_mic_length_get(uint8_t security_level);
3638
static void mac_helper_keytable_pairwise_descriptor_set(struct mac_api_s *api, const uint8_t *key, const uint8_t *mac64, uint8_t attribute_id);
@@ -736,14 +738,19 @@ uint_fast16_t mac_helper_max_payload_size(protocol_interface_info_entry_t *cur,
736738
{
737739
uint16_t max;
738740

739-
max = cur->mac_api->phyMTU - frame_overhead;
741+
if (test_6lowpan_fragmentation_mtu_size_override == 0) {
742+
max = cur->mac_api->phyMTU - frame_overhead;
743+
} else {
744+
max = test_6lowpan_fragmentation_mtu_size_override - frame_overhead;
745+
}
740746

741747
/* But if we want IEEE 802.15.4-2003 compatibility (and it looks like a
742748
* standard PHY), limit ourselves to the 2003 maximum */
743749
if (cur->mac_parameters->MacUnsusecured_2003_cab && max > MAC_IEEE_802_15_4_MAX_MAC_SAFE_PAYLOAD_SIZE &&
744750
cur->mac_api->phyMTU == MAC_IEEE_802_15_4_MAX_PHY_PACKET_SIZE) {
745751
max = MAC_IEEE_802_15_4_MAX_MAC_SAFE_PAYLOAD_SIZE;
746752
}
753+
747754
return max;
748755
}
749756

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct ns_sockaddr;
3030
struct buffer;
3131
struct mac_api_s;
3232

33+
extern uint16_t test_6lowpan_fragmentation_mtu_size_override;
3334

3435
void mac_create_scan_request(mac_scan_type_t type, struct channel_list_s *chanlist, uint8_t scan_duration, struct mlme_scan_s *request);
3536

source/6LoWPAN/ws/ws_test_api.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include "nsconfig.h"
1919

2020
#include <string.h>
21-
#include <ns_list.h>
22-
#include <nsdynmemLIB.h>
23-
#include <net_ws_test.h>
21+
#include "ns_list.h"
22+
#include "nsdynmemLIB.h"
23+
#include "net_ws_test.h"
2424
#include "fhss_config.h"
2525
#include "ws_management_api.h"
2626
#include "mac_api.h"
27+
#include "6LoWPAN/MAC/mac_helper.h"
2728
#include "NWK_INTERFACE/Include/protocol.h"
2829
#include "6LoWPAN/MAC/mac_helper.h"
2930
#include "6LoWPAN/ws/ws_config.h"
@@ -150,4 +151,17 @@ int ws_test_next_gtk_set(int8_t interface_id, uint8_t *gtk[4])
150151
return ws_pae_controller_next_gtk_update(interface_id, gtk);
151152
}
152153

154+
int ws_test_6lowpan_fragmentation_mtu_size_set(int8_t interface_id, uint16_t mtu_size)
155+
{
156+
protocol_interface_info_entry_t *cur;
157+
158+
cur = protocol_stack_interface_info_get_by_id(interface_id);
159+
if (!cur || !ws_info(cur)) {
160+
return -1;
161+
}
162+
163+
test_6lowpan_fragmentation_mtu_size_override = mtu_size;
164+
return 0;
165+
}
166+
153167
#endif // HAVE_WS

0 commit comments

Comments
 (0)