Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/koli'
Browse files Browse the repository at this point in the history
* origin/koli: (254 commits)
  Put smarter dag max rank increment 2048. 0 affect a lot of troubles.
  RPL print update, nud and aneighbour update
  Fix merge compile problems
  Fix LLC unit test's
  LLC data indication and fhss channel set update
  Fix crash which will happen if address registration fail and operation is triggered again by NULL pointer.
  Enabled proper wi-sun security level 6.
  Fix data for 6lowpan when mle is disabled.
  Wi-sun trigle timer update:
  Function name code conventions fix.
  mac_neighbor_info() macro defned for simplify code
  Added check when weighting rule update must do network scan.
  Fix ns_dyn_mem_init stub
  Added Neighbor connected and trusted state update for wisun
  Integrate Mac neighbour table to Thread and 6Lowpan code
  Mac neighbour table update
  Thread Neighbor class update
  Removed almost duplicate mle entry discover for ll64
  Rename some parameters which will help integration to new neighbor table.
  Function parameter and name refactor.
  ...
  • Loading branch information
Arto Kinnunen committed Jul 6, 2018
2 parents f9b23d4 + 2fc10b5 commit 2dc41c0
Show file tree
Hide file tree
Showing 325 changed files with 22,470 additions and 8,436 deletions.
54 changes: 28 additions & 26 deletions nanostack/ccmLIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
#define CCMLIB_H_

#include "ns_types.h"
#include "platform/arm_hal_aes.h"

/**
*
* \file ccmLIB.h
* \brief CCM Library API.
*
* \section ccm-api CCM Library API:
* - ccm_sec_init(), A function to init CCM library.
* - ccm_sec_init(), A function to init CCM context.
* - ccm_process_run(), A function to run configured CCM process.
*
* \section ccm-instruction CCM process sequence:
* 1. Init CCM library by, ccm key, ccm_sec_init()
* 1. Init CCM context by, ccm key, ccm_sec_init()
* - security level
* - 128-bit CCM key
* - mode: AES_CCM_ENCRYPT or AES_CCM_DECRYPT
Expand All @@ -41,11 +42,6 @@
* -If 0 Process ok
* -< 0 MIC fail or parameter fail
*
* \section ccm-mutex CCM Mutex for Multi Thread System
* If you are running a multi thread system and the CCM library will be used for multiple thread, do the following:
* 1. Add compiler flag to library build process CCM_USE_MUTEX.
* 2. Define OS-specific mutex at the application.
* 3. Implement arm_ccm_mutex_lock() arm_ccm_mutex_unlock() function for using the generated and initialized mutex.
*/
#ifdef __cplusplus
extern "C" {
Expand All @@ -63,41 +59,39 @@ extern "C" {
#define AES_CCM_DECRYPT 0x01 /**< Decryption mode */


/**
* \brief A function for locking CCM mutex if the OS is multi thread. If you are using single thread create an empty function.
*/
extern void arm_ccm_mutex_lock(void);
/**
* \brief A function for unlocking CCM mutex if the OS is multi thread. If you are using single thread create an empty function
*/
extern void arm_ccm_mutex_unlock(void);

/*!
* \struct ccm_globals_t
* \brief CCM global structure.
* The structure is used for configuring NONCE, adata and data before calling ccm_process_run().
*/
typedef struct {
uint8_t exp_nonce[15]; /**< CCM NONCE buffer Nonce. */
uint8_t *data_ptr; /**< Pointer to data IN. */
uint16_t data_len; /**< Length of data IN. */
uint8_t exp_nonce[15]; /**< CCM NONCE buffer Nonce. */
uint8_t *data_ptr; /**< Pointer to data IN. */
uint16_t data_len; /**< Length of data IN. */
const uint8_t *adata_ptr; /**< Pointer to authentication data. */
uint16_t adata_len; /**< Length of authentication data. */
uint8_t mic_len; /**< ccm_sec_init() sets here the length of MIC. */
uint8_t *mic; /**< Encrypt process writes MIC. Decrypt reads it and compares it with the MIC obtained from data. */
uint16_t adata_len; /**< Length of authentication data. */
unsigned ccm_encode_mode:1; /**< Encryption modeAES_CCM_ENCRYPT or AES_CCM_DECRYPT. */
unsigned ccm_sec_level:3; /**< Encryption operation security level 0-7. */
unsigned ccm_l_param:4; /**< Can be 2 or 3. 2 when NONCE length is 13 and 3 when 12*/
uint8_t mic_len; /**< ccm_sec_init() sets here the length of MIC. */
uint8_t *mic; /**< Encrypt process writes MIC. Decrypt reads it and compares it with the MIC obtained from data. */
const uint8_t *key_ptr; /**< Encyption key pointer to 128-bit key. */
arm_aes_context_t *aes_context; /**< Allocated AES context. */
} ccm_globals_t;


/**
* \brief A function to initialize the CCM library.
* \brief A function to initialize the CCM context.
* \param ccm_context pointer to initialized XXM context
* \param sec_level Used CCM security level (0-7).
* \param ccm_key Pointer to 128-key.
* \param mode AES_CCM_ENCRYPT or AES_CCM_DECRYPT.
* \param ccm_l Can be 2 or 3. 2 when NONCE length is 13 and 3 when 12. (NONCE length = (15-ccm_l))
*
* \return Pointer to Global CCM parameter buffer.
* \return 0 When parameter fails or CCM is busy.
* \return true when AES context allocation is OK and given parameters.
* \return false CCM parameters or AES context allocation fail.
*/
extern ccm_globals_t *ccm_sec_init(uint8_t sec_level, const uint8_t *ccm_key, uint8_t mode, uint8_t ccm_l);
extern bool ccm_sec_init(ccm_globals_t *ccm_context, uint8_t sec_level, const uint8_t *ccm_key, uint8_t mode, uint8_t ccm_l);

/**
* \brief A function to run the configured CCM process.
Expand All @@ -109,6 +103,14 @@ extern ccm_globals_t *ccm_sec_init(uint8_t sec_level, const uint8_t *ccm_key, ui
* \return -2 Null pointer given to function.
*/
extern int8_t ccm_process_run(ccm_globals_t *ccm_params);

/**
* \brief A function to free aes context. Call only if ccm_process_run() is not called
* \param ccm_params CCM parameters
*
*/
extern void ccm_free(ccm_globals_t *ccm_params);

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 27 additions & 3 deletions nanostack/fhss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,16 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
* @param is_broadcast_addr Destination address type of packet (true if broadcast address).
* @param destination_address Destination MAC address.
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
* @param synch_info Pointer to where FHSS synchronization info is written (if synch frame).
* @param frame_length MSDU length of the frame.
* @param phy_header_length PHY header length.
* @param phy_tail_length PHY tail length.
* @param tx_time TX time.
* @return 0 Success.
* @return -1 Transmission of the packet is currently not allowed, try again.
* @return -2 Invalid api.
* @return -3 Broadcast packet on Unicast channel (not allowed), push packet back to queue.
* @return -4 Synchronization info missing.
*/
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time);

/**
* @brief Check TX permission.
Expand Down Expand Up @@ -152,6 +151,17 @@ typedef uint32_t fhss_read_timestamp(const fhss_api_t *api);
*/
typedef uint16_t fhss_get_retry_period(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);

/**
* @brief Write synchronization info to given pointer.
* @param api FHSS instance.
* @param ptr Pointer to data. Start of written data for Synch frame. Start of IE header for Data frame.
* @param length Length of IE header. Ignored when Synch frame.
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
* @param tx_time TX time must be referenced to the first symbol following the SFD of the transmitted frame.
* @return -1 on fail, write length otherwise.
*/
typedef int16_t fhss_write_synch_info(const fhss_api_t *api, uint8_t *ptr, uint8_t length, int frame_type, uint32_t tx_time);

/**
* @brief Initialize MAC functions.
* @param api FHSS instance.
Expand All @@ -177,6 +187,7 @@ struct fhss_api {
fhss_synch_state_set *synch_state_set; /**< Change synchronization state. */
fhss_read_timestamp *read_timestamp; /**< Read timestamp. */
fhss_get_retry_period *get_retry_period; /**< Get retransmission period. */
fhss_write_synch_info *write_synch_info; /**< Write synchronization info to TX frame*/
fhss_init_callbacks *init_callbacks; /**< Initialize MAC functions. */
};

Expand Down Expand Up @@ -256,6 +267,18 @@ typedef int mac_broadcast_notify(const fhss_api_t *fhss_api, uint32_t broadcast_
*/
typedef int mac_read_coordinator_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address);

/**
* @brief Read synchronization info for a specific peer.
* @param fhss_api FHSS instance.
* @param info_ptr Pointer to info data.
* @param mac_address MAC address pointer.
* @param info_type Type of the read info (UTT-IE, BT-IE, US-IE, BS-IE).
* @param rx_timestamp Time of reception of the element.
* @return >=0 Length of the info.
* @return -1 Fail.
*/
typedef int mac_read_synch_info(const fhss_api_t *fhss_api, uint8_t *info_ptr, uint8_t *mac_address, int info_type, uint32_t rx_timestamp);

/**
* \brief Struct fhss_callback defines functions that software MAC needs to implement.
* Function pointers are passed to FHSS using fhss_init_callbacks function.
Expand All @@ -270,6 +293,7 @@ struct fhss_callback {
mac_tx_poll *tx_poll; /**< Poll TX queue. */
mac_broadcast_notify *broadcast_notify; /**< Broadcast channel notification from FHSS. */
mac_read_coordinator_mac_address *read_coord_mac_address; /**< Read coordinator MAC address. */
mac_read_synch_info *read_synch_info; /**< Read information element for a specific MAC address. */
};

#ifdef __cplusplus
Expand Down
62 changes: 59 additions & 3 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
extern "C" {
#endif

#include "fhss_ws_extension.h"

/**
* @brief WS channel functions.
*/
typedef enum
{
/** Fixed channel. */
WS_FIXED_CHANNEL,
/** TR51 channel function. */
WS_TR51CF,
/** Direct Hash channel function. */
WS_DH1CF,
/** Vendor Defined channel function. */
WS_VENDOR_DEF_CF
} fhss_ws_channel_functions;

/**
* \brief Struct fhss_tuning_parameter defines FHSS tuning parameters.
* All delays are given in microseconds.
Expand Down Expand Up @@ -63,20 +80,59 @@ typedef struct fhss_configuration

} fhss_configuration_t;

/**
* @brief Get channel using vendor defined channel function.
* @param api FHSS instance.
* @param slot Slot number in channel schedule.
* @param eui64 EUI-64 address of node for which the (unicast) schedule is calculated. NULL for broadcast schedule.
* @param bsi Broadcast schedule identifier used in (broadcast) schedule calculation.
* @param number_of_channels Number of channels in schedule.
* @return Channel.
*/
typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uint8_t eui64[8], uint16_t bsi, uint16_t number_of_channels);

/**
* \brief Struct fhss_ws_configuration defines configuration of WS FHSS.
*/
typedef struct fhss_ws_configuration
{
/** WS channel function. */
fhss_ws_channel_functions ws_channel_function;

/** Broadcast schedule identifier. */
uint16_t bsi;

/** Unicast dwell interval. Range: 15-250 milliseconds. */
uint8_t fhss_uc_dwell_interval;

/** Broadcast interval. Duration between broadcast dwell intervals. Range: 0-16777216 milliseconds. */
uint32_t fhss_broadcast_interval;

/** Broadcast dwell interval. Range: 15-250 milliseconds. */
uint8_t fhss_bc_dwell_interval;

/** Channel mask. */
uint32_t channel_mask[8];

/** Vendor defined channel function. */
fhss_vendor_defined_cf *vendor_defined_cf;

} fhss_ws_configuration_t;

/**
* \brief Struct fhss_timer defines interface between FHSS and FHSS platform timer.
* Application must implement FHSS timer driver which is then used by FHSS with this interface.
*/
typedef struct fhss_timer
{
/** Start timeout (1us) */
/** Start timeout (1us). Timer must support multiple simultaneous timeouts */
int (*fhss_timer_start)(uint32_t, void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Stop timeout */
int (*fhss_timer_stop)(const fhss_api_t *fhss_api);
int (*fhss_timer_stop)(void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Get remaining time of started timeout*/
uint32_t (*fhss_get_remaining_slots)(const fhss_api_t *fhss_api);
uint32_t (*fhss_get_remaining_slots)(void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);

/** Get timestamp since initialization of driver. Overflow of 32-bit counter is allowed (1us) */
uint32_t (*fhss_get_timestamp)(const fhss_api_t *fhss_api);
Expand Down
113 changes: 113 additions & 0 deletions nanostack/fhss_ws_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 2015-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* \file fhss_ws_extension.h
* \brief
*/

#ifndef FHSS_WS_EXT_H
#define FHSS_WS_EXT_H

#include "ns_types.h"
#include "fhss_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief unicast_timing_info Unicast timing/hopping schedule information structure.
*/
typedef struct unicast_timing_info {
unsigned unicast_channel_function:3; /**< Unicast schedule channel function */
uint8_t unicast_dwell_interval; /**< Unicast dwell interval */
uint16_t unicast_number_of_channels; /**< Unicast number of channels */
uint_fast24_t ufsi; /**< Unicast fractional sequence interval */
uint32_t utt_rx_timestamp; /**< UTT-IE reception timestamp */
} unicast_timing_info_t;

/**
* @brief broadcast_timing_info Broadcast timing/hopping schedule information structure.
*/
typedef struct broadcast_timing_info {
unsigned broadcast_channel_function:3; /**< Broadcast schedule channel function */
uint8_t broadcast_dwell_interval; /**< Broadcast dwell interval */
uint16_t broadcast_slot; /**< Broadcast slot number */
uint16_t broadcast_schedule_id; /**< Broadcast schedule identifier */
uint_fast24_t broadcast_interval_offset; /**< Broadcast interval offset */
uint32_t broadcast_interval; /**< Broadcast interval */
uint32_t bt_rx_timestamp; /**< BT-IE reception timestamp */
} broadcast_timing_info_t;

/**
* @brief fhss_ws_neighbor_timing_info Neighbor timing/hopping schedule information structure.
*/
typedef struct fhss_ws_neighbor_timing_info {
uint8_t clock_drift; /**< Neighbor clock drift */
uint8_t timing_accuracy; /**< Neighbor timing accuracy */
unicast_timing_info_t uc_timing_info; /**< Neighbor unicast timing info */
broadcast_timing_info_t bc_timing_info; /**< Neighbor broadcast timing info */
uint32_t *excluded_channels; /**< Neighbor excluded channels (bit mask) */
} fhss_ws_neighbor_timing_info_t;

/**
* @brief Get neighbor timing/hopping schedule.
* @param api FHSS instance.
* @param eui64 EUI-64 address of node for which the info is requested.
* @return Neighbor timing/hopping schedule.
*/
typedef fhss_ws_neighbor_timing_info_t *fhss_get_neighbor_info(const fhss_api_t *api, uint8_t eui64[8]);

/**
* @brief Set parent which broadcast channels must be listened by FHSS.
* @param fhss_api FHSS instance.
* @param eui64 EUI-64 address of parent.
* @param bc_timing_info Pointer to parent broadcast timing/hopping schedule info.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info);

/**
* @brief Remove parent which was set by ns_fhss_ws_set_parent function.
* @param fhss_api FHSS instance.
* @param eui64 EUI-64 address of parent.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_ws_remove_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8]);

/**
* @brief Set neighbor timing/hopping schedule request function.
* @param fhss_api FHSS instance.
* @param get_neighbor_info Neighbor info function pointer.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_set_neighbor_info_fp(const fhss_api_t *fhss_api, fhss_get_neighbor_info *get_neighbor_info);

/**
* @brief Set node hop count. Hop count is used to specify TX/RX slot. When hop count is set to 0xFF, TX/RX slots are ignored.
* @param fhss_api FHSS instance.
* @param hop_count Hop count to be set.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_ws_set_hop_count(const fhss_api_t *fhss_api, const uint8_t hop_count);

#ifdef __cplusplus
}
#endif

#endif // FHSS_WS_EXT_H
Loading

0 comments on commit 2dc41c0

Please sign in to comment.