Skip to content

Commit

Permalink
MPX support Integrate
Browse files Browse the repository at this point in the history
Integrated MPX support to Adaptation interface.

Moved Data indication buffer allocate to Adatation interface that we can
share code with MPX data indication.

Updated 8-bit length to 16-bit to mac_helper_max_payload_size() and
mac_helper_frame_overhead()

Upadted and fixed unit test.
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Jan 30, 2018
1 parent 2531c49 commit b2198b3
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 143 deletions.
1 change: 1 addition & 0 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#endif
#include "sw_mac.h"
#include "6LoWPAN/MAC/mac_data_poll.h"
#include "6LoWPAN/MAC/mpx_api.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "platform/arm_hal_interrupt.h"
#include "common_functions.h"
#include "mac_api.h"
#include "6LoWPAN/MAC/mpx_api.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
#include "libNET/src/net_load_balance_internal.h"
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/IPHC_Decode/6lowpan_iphc.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ buffer_t *lowpan_down(buffer_t *buf)
/* RFC 6282+4944 require that we limit compression to the first fragment.
* This check is slightly conservative - always allow 4 for first-fragment header
*/
uint_fast8_t overhead = mac_helper_frame_overhead(cur, buf);
uint_fast16_t overhead = mac_helper_frame_overhead(cur, buf);
uint_fast16_t max_iphc_size = mac_helper_max_payload_size(cur, overhead) - mesh_size - 4;

buf = iphc_compress(&cur->lowpan_contexts, buf, max_iphc_size, stable_only);
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/MAC/mac_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ int8_t mac_helper_mac64_set(protocol_interface_info_entry_t *interface, const ui
* Given a buffer, with address and security flags set, compute the maximum
* MAC payload that could be put in that buffer.
*/
uint_fast16_t mac_helper_max_payload_size(protocol_interface_info_entry_t *cur, uint_fast8_t frame_overhead)
uint_fast16_t mac_helper_max_payload_size(protocol_interface_info_entry_t *cur, uint_fast16_t frame_overhead)
{
uint16_t max;

Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/MAC/mac_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool mac_helper_write_our_addr(struct protocol_interface_info_entry *interface,

int8_t mac_helper_mac64_set(struct protocol_interface_info_entry *interface, const uint8_t *mac64);

uint_fast16_t mac_helper_max_payload_size(struct protocol_interface_info_entry *cur, uint_fast8_t frame_overhead);
uint_fast16_t mac_helper_max_payload_size(struct protocol_interface_info_entry *cur, uint_fast16_t frame_overhead);

uint_fast8_t mac_helper_frame_overhead(struct protocol_interface_info_entry *cur, const struct buffer *buf);

Expand Down
63 changes: 2 additions & 61 deletions source/6LoWPAN/MAC/mac_response_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
#include "mac_mcps.h"
#include "6LoWPAN/MAC/mac_data_poll.h"
#include "6LoWPAN/MAC/mac_response_handler.h"
#include "6LoWPAN/MAC/mpx_api.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"

static bool mac_data_is_broadcast_addr(const sockaddr_t *addr);

#define TRACE_GROUP "MRsH"


Expand Down Expand Up @@ -107,62 +106,10 @@ void mcps_data_confirm_handler( const mac_api_t* api, const mcps_data_conf_t *da
lowpan_adaptation_interface_tx_confirm(info_entry, data);
}

static bool mcps_data_indication_neighbor_validate(int8_t interface_id, const sockaddr_t *addr)
{
/* If MLE is enabled, we will talk if we have an MLE association */
mle_neigh_table_entry_t *mle_entry = mle_class_get_by_link_address(interface_id, addr->address + 2, addr->addr_type);
if (mle_entry && (mle_entry->handshakeReady || mle_entry->thread_commission)) {
return true;
}

/* Otherwise, we don't know them */
return false;

}

void mcps_data_indication_handler( const mac_api_t* api, const mcps_data_ind_t *data_ind )
{
protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id);
buffer_t *buf = buffer_get(data_ind->msduLength);
if (!buf || !info_entry) {
return;
}
uint8_t *ptr;
buffer_data_add(buf, data_ind->msdu_ptr, data_ind->msduLength);
//tr_debug("MAC Paylod size %u %s",data_ind->msduLength, trace_array(data_ind->msdu_ptr, 8));
buf->options.lqi = data_ind->mpduLinkQuality;
buf->options.dbm = data_ind->signal_dbm;
buf->src_sa.addr_type = (addrtype_t)data_ind->SrcAddrMode;
ptr = common_write_16_bit(data_ind->SrcPANId, buf->src_sa.address);
memcpy(ptr, data_ind->SrcAddr, 8);
buf->dst_sa.addr_type = (addrtype_t)data_ind->DstAddrMode;
ptr = common_write_16_bit(data_ind->DstPANId, buf->dst_sa.address);
memcpy(ptr, data_ind->DstAddr, 8);
//Set Link spesific stuff to seperately
buf->link_specific.ieee802_15_4.srcPanId = data_ind->SrcPANId;
buf->link_specific.ieee802_15_4.dstPanId = data_ind->DstPANId;

if (mac_data_is_broadcast_addr(&buf->dst_sa)) {
buf->options.ll_broadcast_rx = true;
}
buf->interface = info_entry;
if (data_ind->Key.SecurityLevel) {
buf->link_specific.ieee802_15_4.fc_security = true;

if (info_entry->mac_security_key_usage_update_cb) {
info_entry->mac_security_key_usage_update_cb(info_entry, &data_ind->Key);
}
} else {
buf->link_specific.ieee802_15_4.fc_security = false;
if (mac_helper_default_security_level_get(info_entry) ||
!mcps_data_indication_neighbor_validate(info_entry->id, &buf->src_sa)) {
//SET By Pass
buf->options.ll_security_bypass_rx = true;
}
}

buf->info = (buffer_info_t)(B_TO_IPV6_TXRX | B_FROM_MAC | B_DIR_UP);
protocol_push(buf);
lowpan_adaptation_interface_data_ind(info_entry, data_ind);
}

void mcps_purge_confirm_handler( const mac_api_t* api, mcps_purge_conf_t *data )
Expand Down Expand Up @@ -306,9 +253,3 @@ void mlme_indication_handler( const mac_api_t* api, mlme_primitive id, const voi
}
}

bool mac_data_is_broadcast_addr(const sockaddr_t *addr)
{
return (addr->addr_type == ADDR_802_15_4_SHORT) &&
(addr->address[2] == 0xFF && addr->address[3] == 0xFF);
}

1 change: 1 addition & 0 deletions source/6LoWPAN/Thread/thread_management_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "Service_Libs/blacklist/blacklist.h"
#include "6LoWPAN/MAC/mac_helper.h"
#include "6LoWPAN/MAC/mac_pairwise_key.h"
#include "6LoWPAN/MAC/mpx_api.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "mac_common_defines.h"
#include "mlme.h"
Expand Down
Loading

0 comments on commit b2198b3

Please sign in to comment.