Skip to content

Commit

Permalink
mac_neighbor_info() macro defned for simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Jun 25, 2018
1 parent 41b84e4 commit 1350bc5
Show file tree
Hide file tree
Showing 30 changed files with 150 additions and 148 deletions.
18 changes: 9 additions & 9 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ static int8_t mle_set_link_priority(protocol_interface_info_entry_t *cur, const
uint8_t mac64[8];
mac_neighbor_table_entry_t *entry;
if (!memcmp(address, ADDR_SHORT_ADR_SUFFIC, 6)) {
entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, address + 6, ADDR_802_15_4_SHORT);
entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), address + 6, ADDR_802_15_4_SHORT);
} else {

memcpy(mac64, address, 8);
mac64[0] ^= 2;
entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, mac64, ADDR_802_15_4_LONG);
entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), mac64, ADDR_802_15_4_LONG);
}

if (!entry) {
Expand Down Expand Up @@ -483,7 +483,7 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
return 0;
}

mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, addr_ptr + PAN_ID_LEN, addr_type);
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);

if (entry) {
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
Expand Down Expand Up @@ -516,7 +516,7 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
return 0;
}

mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, addr_ptr + PAN_ID_LEN, addr_type);
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);

if (entry) {
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
Expand All @@ -542,7 +542,7 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
if (!cur) {
return;
}
mac_neighbor_table_list_t *mac_table_list = &cur->mac_parameters->mac_neighbor_table->neighbour_list;
mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list;

ns_list_foreach(mac_neighbor_table_entry_t, entry, mac_table_list) {
if (priority == PRIORITY_1ST && entry->link_role == PRIORITY_PARENT_NEIGHBOUR) {
Expand All @@ -566,7 +566,7 @@ int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_ent
{
int8_t ret_val = -1;

mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, eui64, ADDR_802_15_4_LONG);
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), eui64, ADDR_802_15_4_LONG);
if (entry) {
if (memcmp(iid, ADDR_SHORT_ADR_SUFFIC, 6) == 0) {
iid += 6;
Expand All @@ -575,7 +575,7 @@ int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_ent
}
if (!entry->ffd_device) {
if (entry->connected_device) {
mac_neighbor_table_neighbor_refresh(cur->mac_parameters->mac_neighbor_table, entry, entry->link_lifetime);
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry, entry->link_lifetime);
}
ret_val = 1;
} else {
Expand All @@ -587,9 +587,9 @@ int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_ent

int8_t protocol_6lowpan_neighbor_remove(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, addrtype_t type)
{
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, address_ptr, type);
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), address_ptr, type);
if (entry) {
mac_neighbor_table_neighbor_remove(cur->mac_parameters->mac_neighbor_table, entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), entry);
}
return 0;
}
Expand Down
44 changes: 22 additions & 22 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static bool protocol_6lowpan_challenge_callback(int8_t interface_id, uint16_t ms
memcpy(mac64, ll64_ptr + 8, 8);
mac64[0] ^= 2;

mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(cur_interface->mac_parameters->mac_neighbor_table, mac64, ADDR_802_15_4_LONG);
mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur_interface), mac64, ADDR_802_15_4_LONG);

if (!neig_info) {
return false;//Why entry is removed before timeout??
Expand All @@ -222,7 +222,7 @@ static bool protocol_6lowpan_challenge_callback(int8_t interface_id, uint16_t ms

if (usedAllRetries) {
//GET entry
mac_neighbor_table_neighbor_remove(cur_interface->mac_parameters->mac_neighbor_table, neig_info);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur_interface), neig_info);
return false;
}

Expand Down Expand Up @@ -407,7 +407,7 @@ static uint8_t *mle_table_set_neighbours(protocol_interface_info_entry_t *cur, u
// defaults: complete, 2 bytes long link-layer address
link_flags_ptr = ptr++;
*link_flags_ptr = 0x81;
if (mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, short_temp,ADDR_802_15_4_SHORT)) {
if (mac_neighbor_table_address_discover(mac_neighbor_info(cur), short_temp,ADDR_802_15_4_SHORT)) {
*link_flags_ptr |= 0x07;
neigh_count_max = mle_advert_neigh_cnt(cur, false);
} else {
Expand Down Expand Up @@ -490,7 +490,7 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
return 0;
}

if (mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, short_temp,ADDR_802_15_4_SHORT)) {
if (mac_neighbor_table_address_discover(mac_neighbor_info(cur), short_temp,ADDR_802_15_4_SHORT)) {
neig_cache_size += mle_advert_neigh_cnt(cur, false) * 10;
} else {
neig_cache_size += mle_advert_neigh_cnt(cur, true) << 2;
Expand Down Expand Up @@ -565,7 +565,7 @@ static void mle_neigh_time_and_mode_update(mac_neighbor_table_entry_t *entry_tem
timeout_tlv = mle_6lowpan_data->host_lifetime;
}
}
mac_neighbor_table_neighbor_refresh(cur->mac_parameters->mac_neighbor_table, entry_temp, timeout_tlv);
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_temp, timeout_tlv);
}

static void mle_neigh_entry_update_by_mle_tlv_list(int8_t interface_id, mac_neighbor_table_entry_t *entry_temp, uint8_t *tlv_ptr, uint16_t tlv_length, uint8_t *mac64, uint16_t short_address)
Expand Down Expand Up @@ -729,10 +729,10 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,

static void protocol_6lowpan_link_reject_handler(protocol_interface_info_entry_t *cur, uint8_t *ll64)
{
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, ll64, false, NULL);
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), ll64, false, NULL);
tr_debug("MLE link reject");
if (mac_entry) {
mac_neighbor_table_neighbor_remove(cur->mac_parameters->mac_neighbor_table, mac_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), mac_entry);
}
}

Expand Down Expand Up @@ -1048,7 +1048,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
mle_6lowpan_data->link_req_token_bucket--;
} else {
//Update only old information based on link request
entry_temp = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, mle_msg->packet_src_address, false, NULL);
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
if (entry_temp) {
mle_neigh_time_and_mode_update(entry_temp,mle_msg);
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
Expand Down Expand Up @@ -1084,11 +1084,11 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
}

tr_debug("Accept & Request");
entry_temp = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, mle_msg->packet_src_address, false, NULL);
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
if (!entry_temp) {
// If there is space for neighbors try to allocate new entry
if (mle_6lowpan_neighbor_limit_check(mle_msg, true)) {
entry_temp = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, mle_msg->packet_src_address, true, NULL);
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, true, NULL);
}
}

Expand Down Expand Up @@ -1148,7 +1148,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
t_ptr = mle_tlv_info.dataPtr;
mode = *t_ptr;
}
entry_temp = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, mle_msg->packet_src_address, false, NULL);
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
if (!entry_temp) {
if ((mode & MLE_DEV_MASK) == MLE_FFD_DEV) {
// If there is space for neighbors synchronizes to new router
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
//Possible remove
if ((mode & MLE_DEV_MASK) == MLE_RFD_DEV) {
//Remove Entry
mac_neighbor_table_neighbor_remove(cur->mac_parameters->mac_neighbor_table, entry_temp);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), entry_temp);
tr_error("MLE adv: Own address not found");
return;
}
Expand All @@ -1196,7 +1196,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
mle_neigh_entry_update_by_mle_tlv_list(cur->id,entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex);
if (entry_temp->connected_device) {
mac_neighbor_table_neighbor_refresh(cur->mac_parameters->mac_neighbor_table, entry_temp, entry_temp->link_lifetime);
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_temp, entry_temp->link_lifetime);
}
}
break;
Expand Down Expand Up @@ -1294,7 +1294,7 @@ static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_

// Sends REJECT
mle_service_reject_message_build(cur_interface->id, ll64, false);
mac_neighbor_table_neighbor_remove(cur_interface->mac_parameters->mac_neighbor_table, entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur_interface), entry);

// Adds purged neighbor to blacklist so that it is not added right away back from advertisement
blacklist_update(ll64, false);
Expand Down Expand Up @@ -1679,16 +1679,16 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
cur->mac_security_key_usage_update_cb = arm_6lowpan_security_key_update_cb;
//Allocate MLE class here
//Deallocate old here
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
mac_neighbor_table_delete(mac_neighbor_info(cur));
mac_description_storage_size_t buffer;
//Read MAC device table sizes
if (cur->mac_api->mac_storage_sizes_get(cur->mac_api, &buffer) != 0) {
return -1;
}

cur->mac_parameters->mac_neighbor_table = mac_neighbor_table_create(buffer.device_decription_table_size, lowpan_neighbor_entry_remove_notify
mac_neighbor_info(cur) = mac_neighbor_table_create(buffer.device_decription_table_size, lowpan_neighbor_entry_remove_notify
, lowpan_neighbor_entry_nud_notify, cur);
if (!cur->mac_parameters->mac_neighbor_table) {
if (!mac_neighbor_info(cur)) {
return -1;
}

Expand Down Expand Up @@ -1973,7 +1973,7 @@ static void protocol_6lowpan_nd_ready(protocol_interface_info_entry_t *cur)
addrtype_t addrType;
uint8_t tempAddr[8];
addrType = mac_helper_coordinator_address_get(cur, tempAddr);
mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, tempAddr, addrType);
mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur), tempAddr, addrType);

if (neig_info) {
if (neig_info->lifetime > MLE_TABLE_CHALLENGE_TIMER) {
Expand Down Expand Up @@ -2798,10 +2798,10 @@ static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_statu

break;
case MLME_DATA_POLL_NOTIFICATION:
entry_ptr = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, status->SrcAddr, status->SrcAddrMode);
entry_ptr = mac_neighbor_table_address_discover(mac_neighbor_info(cur), status->SrcAddr, status->SrcAddrMode);
if (entry_ptr) {
// Refresh Timeout
mac_neighbor_table_neighbor_refresh(cur->mac_parameters->mac_neighbor_table, entry_ptr, entry_ptr->link_lifetime);
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_ptr, entry_ptr->link_lifetime);
}
break;
default:
Expand All @@ -2817,13 +2817,13 @@ bool lowpan_neighbour_data_clean(int8_t interface_id, const uint8_t *link_local_
return false;
}
bool return_value = false;
mac_neighbor_table_entry_t *neigh_entry = mac_neighbor_entry_get_by_ll64(cur->mac_parameters->mac_neighbor_table, link_local_address, false, NULL);
mac_neighbor_table_entry_t *neigh_entry = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), link_local_address, false, NULL);
if (neigh_entry) {
//Remove entry
if (neigh_entry->link_role == PRIORITY_PARENT_NEIGHBOUR || neigh_entry->link_role == SECONDARY_PARENT_NEIGHBOUR) {
return_value = true;
}
mac_neighbor_table_neighbor_remove(cur->mac_parameters->mac_neighbor_table, neigh_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), neigh_entry);
}
return return_value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur)
/* Change Active -> Idle */
/* Disable Protocols Timers */
if (!thread_info(cur)) {
mac_neighbor_table_neighbor_list_clean(cur->mac_parameters->mac_neighbor_table);
mac_neighbor_table_neighbor_list_clean(mac_neighbor_info(cur));
#ifndef NO_MLE
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {

Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/MAC/mac_data_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void mac_poll_timer_trig(uint32_t poll_time, protocol_interface_info_entry_t *cu
}
static mac_neighbor_table_entry_t *neighbor_data_poll_referesh(protocol_interface_info_entry_t *cur, uint8_t *address, addrtype_t type)
{
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(cur->mac_parameters->mac_neighbor_table, address, type);
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), address, type);
if (!entry) {
return NULL;
}
Expand Down
16 changes: 8 additions & 8 deletions source/6LoWPAN/MAC/mac_pairwise_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ static void mac_pairwise_key_list_free(protocol_interface_info_entry_t *interfac
mac_neighbor_table_entry_t *cur_entry;
mac_pairwise_key_info_t *cur = main_list->mac_pairwise_key_table;
for (uint8_t i = 0; i< main_list->key_table_size; i++) {
cur_entry = mac_neighbor_table_attribute_discover(interface->mac_parameters->mac_neighbor_table, cur->device_descriptor_attribute);
cur_entry = mac_neighbor_table_attribute_discover(mac_neighbor_info(interface), cur->device_descriptor_attribute);
if (cur_entry) {
mac_neighbor_table_neighbor_remove(interface->mac_parameters->mac_neighbor_table, cur_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(interface), cur_entry);
}
mac_helper_security_pairwisekey_set(interface, NULL, NULL, cur->key_decriptor_attribute);
}
Expand Down Expand Up @@ -267,20 +267,20 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
}

//Allocate mle entry
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_mac64(interface->mac_parameters->mac_neighbor_table, eui64, true, &new_entry_created);
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_mac64(mac_neighbor_info(interface), eui64, true, &new_entry_created);
if (!mac_entry) {
return -1;
}

mac_neighbor_table_trusted_neighbor(interface->mac_parameters->mac_neighbor_table, mac_entry, true);
mac_neighbor_table_trusted_neighbor(mac_neighbor_info(interface), mac_entry, true);
mac_entry->mac16 = 0xffff;

//Allocate key description

mac_pairwise_key_info_t *key_desc = mac_pairwise_key_info_get(main_list, mac_entry->index);

if (!key_desc) {
mac_neighbor_table_neighbor_remove(interface->mac_parameters->mac_neighbor_table, mac_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(interface), mac_entry);
return -1;
}

Expand All @@ -291,7 +291,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
//set key descriptor
if (mac_helper_security_pairwisekey_set(interface, key, eui64, key_desc->key_decriptor_attribute) != 0) {
main_list->key_table_size--;
mac_neighbor_table_neighbor_remove(interface->mac_parameters->mac_neighbor_table, mac_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(interface), mac_entry);
return -1;
}

Expand All @@ -312,7 +312,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
return -1;
}
//Get from mac
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_mac64(interface->mac_parameters->mac_neighbor_table, eui64, true, NULL);
mac_neighbor_table_entry_t *mac_entry = mac_neighbor_entry_get_by_mac64(mac_neighbor_info(interface), eui64, true, NULL);
if (!mac_entry) {
return -1;
}
Expand All @@ -327,7 +327,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
//kill Entry & overwrite key
mac_helper_security_pairwisekey_set(interface, NULL, NULL, key_attribute);

mac_neighbor_table_neighbor_remove(interface->mac_parameters->mac_neighbor_table, mac_entry);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(interface), mac_entry);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/MAC/mac_response_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void mac_mlme_device_table_confirmation_handle(protocol_interface_info_en

if (confirmation->status == MLME_SUCCESS) {
//GET ME table by extended mac64 address
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(info_entry->mac_parameters->mac_neighbor_table, descpription->ExtAddress, ADDR_802_15_4_LONG);
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(info_entry), descpription->ExtAddress, ADDR_802_15_4_LONG);

if (!entry) {
return;
Expand Down
Loading

0 comments on commit 1350bc5

Please sign in to comment.