Skip to content

Commit

Permalink
Rename and refactor structures and function names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Mar 6, 2018
1 parent b037628 commit e6bac6a
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 81 deletions.
37 changes: 19 additions & 18 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -16,6 +16,7 @@
*/



#include <string.h>
#include "nsconfig.h"
#include "ns_types.h"
Expand All @@ -35,7 +36,6 @@
#include "6LoWPAN/ws/ws_common_defines.h"
#include "6LoWPAN/ws/ws_common.h"
#include "6LoWPAN/ws/ws_bootstrap.h"
#include "6LoWPAN/ws/ws_neighbour_class.h"
#include "RPL/rpl_control.h"
#include "RPL/rpl_data.h"
#include "Common_Protocols/icmpv6.h"
Expand All @@ -44,6 +44,7 @@
#include "Service_Libs/Trickle/trickle.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "6LoWPAN/ws/ws_llc.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "platform/topo_trace.h"
Expand Down Expand Up @@ -261,7 +262,7 @@ static bool ws_bootstrap_network_name_matches(const struct mcps_data_ie_list *ie
return true;
}

static bool ws_bootstrap_unicast_schedule_read(uint8_t *ptr, uint16_t length, ws_hoopping_schedule_t *uc_hopping)
static bool ws_bootstrap_unicast_schedule_read(uint8_t *ptr, uint16_t length, ws_hopping_schedule_t *uc_hopping)
{
mac_nested_payload_IE_t nested_payload_ie;
nested_payload_ie.id = WP_PAYLOAD_IE_US_TYPE;
Expand Down Expand Up @@ -358,7 +359,7 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
}

ws_pan_information_t pan_information;
ws_hoopping_schedule_t hopping_schedule = { 0 };
ws_hopping_schedule_t hopping_schedule = { 0 };

if (!ws_bootstrap_pan_information_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) {
// Corrupted
Expand All @@ -383,15 +384,15 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
if (!neighbor) {
return;
}
ws_neighbour_class_entry_t *ws_neighbor = ws_neighbour_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
if (!ws_neighbor) {
return;
}

ws_neighbor->fhhs_data.utt_timestamp = data->timestamp;
ws_neighbor->fhhs_data.ufsi = ufsi;
ws_neighbor->fhhs_data.channel_function = hopping_schedule.channel_function;
ws_neighbor->fhhs_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
ws_neighbor->fhss_data.ufsi = ufsi;
ws_neighbor->fhss_data.channel_function = hopping_schedule.channel_function;
ws_neighbor->fhss_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;



Expand Down Expand Up @@ -439,7 +440,7 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
}

uint_fast24_t ufsi;
ws_hoopping_schedule_t hopping_schedule = { 0 };
ws_hopping_schedule_t hopping_schedule = { 0 };

if (!ws_bootstrap_ufsi_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ufsi)) {
// Corrupted
Expand All @@ -458,15 +459,15 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter
if (!neighbor) {
return;
}
ws_neighbour_class_entry_t *ws_neighbor = ws_neighbour_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
if (!ws_neighbor) {
return;
}

ws_neighbor->fhhs_data.utt_timestamp = data->timestamp;
ws_neighbor->fhhs_data.ufsi = ufsi;
ws_neighbor->fhhs_data.channel_function = hopping_schedule.channel_function;
ws_neighbor->fhhs_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
ws_neighbor->fhss_data.ufsi = ufsi;
ws_neighbor->fhss_data.channel_function = hopping_schedule.channel_function;
ws_neighbor->fhss_data.unicast_dwell = hopping_schedule.fhss_uc_dwell_interval;

trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement);
}
Expand Down Expand Up @@ -537,7 +538,7 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
mac_helper_devicetable_remove(cur->mac_api, entry_ptr->index);

//Remove WS neighbor data
ws_neighbour_class_entry_remove(&cur->ws_info->neighbor_storage, entry_ptr->index);
ws_neighbor_class_entry_remove(&cur->ws_info->neighbor_storage, entry_ptr->index);
topo_trace(TOPOLOGY_MLE, entry_ptr->ext64, TOPO_REMOVE);

//TODO Remove ETX neighbor
Expand Down Expand Up @@ -566,7 +567,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
{
int ret_val = 0;

ws_neighbour_class_t neigh_info;
ws_neighbor_class_t neigh_info;
neigh_info.neigh_info_list = NULL;
neigh_info.list_size = 0;
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
Expand Down Expand Up @@ -599,7 +600,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
return -3;
}

if (!ws_neighbour_class_alloc(&neigh_info, buffer.device_decription_table_size)) {
if (!ws_neighbor_class_alloc(&neigh_info, buffer.device_decription_table_size)) {
ret_val = -1;
goto init_fail;
}
Expand Down Expand Up @@ -653,7 +654,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
init_fail:
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
ws_neighbour_class_dealloc(&neigh_info);
ws_neighbor_class_dealloc(&neigh_info);
ws_llc_delete(cur);
return ret_val;
}
Expand Down
9 changes: 5 additions & 4 deletions source/6LoWPAN/ws/ws_common.h
Expand Up @@ -17,14 +17,15 @@
#ifndef WS_COMMON_H_
#define WS_COMMON_H_

#include <6LoWPAN/ws/ws_neighbour_class.h>

#include "ns_types.h"
#include "fhss_api.h"
#include "fhss_config.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"

struct ws_pan_information_s;
struct ws_neighbour_class_s;
struct ws_neighbor_class_s;

typedef struct parent_info_s {
uint16_t pan_id; /**< PAN ID */
Expand All @@ -47,8 +48,8 @@ typedef struct ws_info_s {
uint8_t gtkhash[32];

struct ws_pan_information_s pan_configuration;
ws_hoopping_schedule_t hopping_schdule;
struct ws_neighbour_class_s neighbor_storage;
ws_hopping_schedule_t hopping_schdule;
struct ws_neighbor_class_s neighbor_storage;
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
} ws_info_t;

Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/ws/ws_common_defines.h
Expand Up @@ -64,9 +64,9 @@ typedef struct ws_pan_information_s {
} ws_pan_information_t;

/**
* @brief ws_hoopping_schedule_t Chanel hopping schedule information
* @brief ws_hopping_schedule_t Chanel hopping schedule information
*/
typedef struct ws_hoopping_schedule_s {
typedef struct ws_hopping_schedule_s {
uint8_t fhss_uc_dwell_interval;
uint8_t fhss_bc_dwell_interval;
uint8_t regulatory_domain; /**< PHY regulatory domain default to "KR" 0x09 */
Expand All @@ -83,7 +83,7 @@ typedef struct ws_hoopping_schedule_s {
uint32_t fhss_broadcast_interval;
uint32_t channel_mask[8];
uint_fast24_t ch0_freq; // Default should be derived from regulatory domain
} ws_hoopping_schedule_t;
} ws_hopping_schedule_t;


#define MPX_KEY_MANAGEMENT_ENC_USER_ID 0x0001 /**< MPX Key management user ID */
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_ie_lib.c
Expand Up @@ -32,7 +32,7 @@ static uint8_t *ws_wh_header_base_write(uint8_t *ptr, uint16_t length, uint8_t t
return ptr;
}

uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hoopping_schedule_s *hopping_schedule, bool unicast_schedule)
uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hopping_schedule_s *hopping_schedule, bool unicast_schedule)
{
uint16_t length;
if (unicast_schedule) {
Expand Down Expand Up @@ -122,7 +122,7 @@ uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length)
return mac_ie_payload_base_write(ptr, WS_WP_NESTED_IE, length);
}

uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hoopping_schedule_s *hopping_schedule, bool unicast_schedule)
uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hopping_schedule_s *hopping_schedule, bool unicast_schedule)
{
//Calculate length
uint16_t length = ws_wp_nested_hopping_schedule_length(hopping_schedule, unicast_schedule);
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_ie_lib.h
Expand Up @@ -29,12 +29,12 @@ uint8_t *ws_wh_vh_write(uint8_t *ptr, uint8_t *vendor_header, uint8_t vendor_hea

/* WS_WP_NESTED PAYLOD IE */
uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length);
uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hoopping_schedule_s *hopping_schedule, bool unicast_schedule);
uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hopping_schedule_s *hopping_schedule, bool unicast_schedule);
uint8_t *ws_wp_nested_vp_write(uint8_t *ptr, uint8_t * vendor_payload, uint16_t vendor_payload_length);
uint8_t *ws_wp_nested_pan_info_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration);
uint8_t *ws_wp_nested_netname_write(uint8_t *ptr, uint8_t *network_name, uint8_t network_name_length);
uint8_t *ws_wp_nested_pan_ver_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration);
uint8_t *ws_wp_nested_gtkhash_write(uint8_t *ptr, uint8_t *gtkhash, uint8_t gtkhash_length);
uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hoopping_schedule_s *hopping_schedule, bool unicast_schedule);
uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hopping_schedule_s *hopping_schedule, bool unicast_schedule);

#endif /* WS_IE_LIB_H_ */
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_llc.h
Expand Up @@ -24,7 +24,7 @@ struct mcps_data_ie_list;
struct channel_list_s;
struct ws_pan_information_s;
struct mlme_security_s;
struct ws_hoopping_schedule_s;
struct ws_hopping_schedule_s;


/**
Expand Down Expand Up @@ -174,7 +174,7 @@ void ws_llc_set_pan_information_pointer(struct protocol_interface_info_entry *in
* @param hopping_schedule pointer to Channel hopping schedule
*
*/
void ws_llc_hopping_schedule_config(struct protocol_interface_info_entry *interface, struct ws_hoopping_schedule_s *hopping_schedule);
void ws_llc_hopping_schedule_config(struct protocol_interface_info_entry *interface, struct ws_hopping_schedule_s *hopping_schedule);



Expand Down
21 changes: 11 additions & 10 deletions source/6LoWPAN/ws/ws_llc_data_service.c
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/


#include "nsconfig.h"
#include <string.h>
#include "ns_types.h"
Expand All @@ -33,7 +34,7 @@
#include "6LoWPAN/ws/ws_ie_lib.h"
#include "6LoWPAN/ws/ws_llc.h"
#include "6LoWPAN/ws/ws_mpx_header.h"
#include "6LoWPAN/ws/ws_neighbour_class.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"

#ifdef HAVE_WS
Expand Down Expand Up @@ -64,7 +65,7 @@ typedef struct {
uint8_t vendor_header_length; /**< Vendor spesific header length */
uint8_t gtkhash_length; /**< GTK hash length */
ws_pan_information_t *pan_congiguration; /**< Pan configururation */
struct ws_hoopping_schedule_s *hopping_schedule;/**< Channel hopping schedule */
struct ws_hopping_schedule_s *hopping_schedule;/**< Channel hopping schedule */
uint8_t *gtkhash; /**< Pointer to GTK HASH user must give pointer which include 4 64-bit HASH array */
uint8_t *network_name; /**< Network name */
uint8_t *vendor_header_data; /**< Vendor spesific header data */
Expand Down Expand Up @@ -409,24 +410,24 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
}
protocol_interface_info_entry_t *interface = base->interface_ptr;

ws_neighbour_class_entry_t * ws_neighbor = NULL;
ws_neighbor_class_entry_t * ws_neighbor = NULL;
mac_neighbor_table_entry_t *neighbor = mac_neighbor_table_address_discover(interface->mac_parameters->mac_neighbor_table, data->SrcAddr, data->SrcAddrMode);
if (neighbor) {
ws_neighbor = ws_neighbour_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index);
ws_neighbor = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index);
}


const uint8_t *ptr = utt_ie.content_ptr;
message_type = *ptr++ & 0x0f;
if (ws_neighbor) {
ws_neighbor->fhhs_data.utt_timestamp = data->timestamp;
ws_neighbor->fhhs_data.ufsi = common_read_24_bit_inverse(ptr);
ws_neighbor->fhss_data.utt_timestamp = data->timestamp;
ws_neighbor->fhss_data.ufsi = common_read_24_bit_inverse(ptr);
//Update BT if it is part of message
if (5 == mac_ie_header_sub_id_discover(ie_ext->headerIeList, ie_ext->headerIeListLength, &utt_ie, WH_IE_BT_TYPE)) {
ptr = utt_ie.content_ptr;
ws_neighbor->fhhs_data.bt_timestamp = data->timestamp;
ws_neighbor->fhhs_data.broadcast_slot_number = common_read_16_bit_inverse(ptr);
ws_neighbor->fhhs_data.broadcast_interval = common_read_24_bit_inverse(ptr + 2);
ws_neighbor->fhss_data.bt_timestamp = data->timestamp;
ws_neighbor->fhss_data.broadcast_slot_number = common_read_16_bit_inverse(ptr);
ws_neighbor->fhss_data.broadcast_interval = common_read_24_bit_inverse(ptr + 2);
}

//Refresh Neighbor if unicast
Expand Down Expand Up @@ -900,7 +901,7 @@ void ws_llc_set_pan_information_pointer(struct protocol_interface_info_entry *in
base->ie_params.pan_congiguration = pan_information_pointer;
}

void ws_llc_hopping_schedule_config(struct protocol_interface_info_entry *interface, struct ws_hoopping_schedule_s *hopping_schedule)
void ws_llc_hopping_schedule_config(struct protocol_interface_info_entry *interface, struct ws_hopping_schedule_s *hopping_schedule)
{
llc_data_base_t *base = ws_llc_discover_by_interface(interface);
if (!base) {
Expand Down
Expand Up @@ -15,53 +15,54 @@
* limitations under the License.
*/


#include "nsconfig.h"
#include <string.h>
#include "ns_types.h"
#include "ns_list.h"
#include "ns_trace.h"
#include "nsdynmemLIB.h"
#include "6LoWPAN/ws/ws_neighbour_class.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"

bool ws_neighbour_class_alloc(ws_neighbour_class_t *class_data, uint8_t list_size)
bool ws_neighbor_class_alloc(ws_neighbor_class_t *class_data, uint8_t list_size)
{

class_data->neigh_info_list = ns_dyn_mem_alloc(sizeof(ws_neighbour_class_entry_t) * list_size);
class_data->neigh_info_list = ns_dyn_mem_alloc(sizeof(ws_neighbor_class_entry_t) * list_size);
if (!class_data->neigh_info_list) {
return false;
}

class_data->list_size = list_size;
ws_neighbour_class_entry_t * list_ptr = class_data->neigh_info_list;
ws_neighbor_class_entry_t * list_ptr = class_data->neigh_info_list;
for (uint8_t i = 0; i< list_size; i++) {
memset(list_ptr, 0, sizeof(ws_neighbour_class_entry_t));
memset(list_ptr, 0, sizeof(ws_neighbor_class_entry_t));
list_ptr++;
}
return true;
}


void ws_neighbour_class_dealloc(ws_neighbour_class_t *class_data)
void ws_neighbor_class_dealloc(ws_neighbor_class_t *class_data)
{
ns_dyn_mem_free(class_data->neigh_info_list);
class_data->neigh_info_list = NULL;
class_data->list_size = 0;
}

ws_neighbour_class_entry_t * ws_neighbour_class_entry_get(ws_neighbour_class_t *class_data, uint8_t attribute_index)
ws_neighbor_class_entry_t * ws_neighbor_class_entry_get(ws_neighbor_class_t *class_data, uint8_t attribute_index)
{
if (!class_data->neigh_info_list || attribute_index >= class_data->list_size) {
return NULL;
}

ws_neighbour_class_entry_t *entry = class_data->neigh_info_list + attribute_index;
ws_neighbor_class_entry_t *entry = class_data->neigh_info_list + attribute_index;
return entry;
}

void ws_neighbour_class_entry_remove(ws_neighbour_class_t *class_data, uint8_t attribute_index)
void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t attribute_index)
{
ws_neighbour_class_entry_t *entry = ws_neighbour_class_entry_get(class_data, attribute_index);
ws_neighbor_class_entry_t *entry = ws_neighbor_class_entry_get(class_data, attribute_index);
if (entry) {
memset(entry, 0, sizeof(ws_neighbour_class_entry_t));
memset(entry, 0, sizeof(ws_neighbor_class_entry_t));
}
}

0 comments on commit e6bac6a

Please sign in to comment.