Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers thread_common.h Source File

thread_common.h

00001 /*
00002  * Copyright (c) 2014-2019, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: BSD-3-Clause
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holder nor the
00014  *    names of its contributors may be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 #ifndef LOWPAN_THREAD_H_
00030 #define LOWPAN_THREAD_H_
00031 
00032 #include "ns_list.h"
00033 #include "libDHCPv6/libDHCPv6.h"
00034 #include "libDHCPv6/libDHCPv6_server.h"
00035 #include "6LoWPAN/Thread/thread_routing.h"
00036 #include "6LoWPAN/Thread/thread_network_data_storage.h"
00037 #include "thread_management_if.h"
00038 #include "thread_commissioning_api.h"
00039 #include "thread_border_router_api.h"
00040 #include "eventOS_event_timer.h"
00041 #include "MLE/mle_tlv.h"
00042 
00043 struct mac_neighbor_table_entry;
00044 
00045 #define MAX_MLE_CHALLENGE_LENGTH 32
00046 
00047 /*
00048  * How long a Leader must wait after a router ID has become unassigned before it can be reused.
00049  *
00050  */
00051 #define ROUTER_ID_REUSE_DELAY 100 //Seconds
00052 
00053 #define LEADER_NVM_SYNC_DELAY 30 // Leader router ids write delay to NVM
00054 
00055 #define ROUTER_ID_INFINITY_DELAY 90 //Seconds
00056 
00057 #define NETWORK_ID_TIMEOUT 120 //seconds
00058 
00059 // Values when adverticements are made faster when leader connection is restored
00060 #define NETWORK_ID_SPEEDUP 55 //seconds
00061 #define NETWORK_ID_SPEEDUP_MAX 80 //seconds
00062 
00063 #define DHCPV6_ENTERPRISE_THREAD 0x0000AFAA
00064 #define DHCPV6_OPTION_VENDOR_SPESIFIC_INFO_LEN 0x0011
00065 #define DHCPV6_ROUTER_ID_OPTION 0x0000
00066 #define DHCPV6_ROUTER_ID_OPTION_LEN 0x0009
00067 
00068 #define THREAD_KEY_INDEX(seq) ((uint8_t) (((seq) & 0x0000007f) + 1))
00069 
00070 extern uint8_t thread_version;
00071 extern uint8_t thread_max_mcast_addr;
00072 extern uint32_t thread_delay_timer_default;
00073 extern uint32_t thread_router_selection_jitter;
00074 extern uint16_t thread_joiner_port;
00075 
00076 typedef enum {
00077     THREAD_STATE_NETWORK_DISCOVER,      // Not commissioned to Thread network
00078     THREAD_STATE_REATTACH,              // Connection to leader lost, searching for new parent
00079     THREAD_STATE_REATTACH_RETRY,        // Connection to leader lost, searching for new parent with REED bit is set
00080     THREAD_STATE_ATTACH_ANY,            // Searching for all partitions with leader connectivity
00081     THREAD_STATE_CONNECTED,             // Attached to Thread network - can't route
00082     THREAD_STATE_CONNECTED_ROUTER,      // Attached to Thread network - Routing enabled
00083 } thread_attach_state_e;
00084 
00085 typedef enum {
00086     THREAD_DEVICE_MODE_ROUTER,
00087     THREAD_DEVICE_MODE_FULL_END_DEVICE,
00088     THREAD_DEVICE_MODE_END_DEVICE,
00089     THREAD_DEVICE_MODE_SLEEPY_END_DEVICE,
00090 } thread_attach_device_mode_e;
00091 
00092 typedef enum {
00093     THREAD_COMMISSIONER_NOT_REGISTERED,
00094     THREAD_COMMISSIONER_REGISTRATION_OBSOLETE,
00095     THREAD_COMMISSIONER_REGISTERED
00096 } thread_commissioner_register_status_e;
00097 
00098 typedef struct thread_neigh_table_entry_s {
00099     uint8_t         mlEid[8];
00100     uint32_t        last_contact_time;  /*!< monotonic time - hard to define "contact"; used for Thread Leasequery replies */
00101     uint16_t        link_margin;
00102     bool secured_data_request: 1;
00103     bool request_full_data_set: 1;
00104 } thread_neigh_table_entry_t ;
00105 
00106 /**
00107  * Neighbor info data base
00108  */
00109 typedef struct thread_neighbor_class_s {
00110     thread_neigh_table_entry_t *neigh_info_list ;          /*!< Allocated Neighbour info array*/
00111     uint8_t list_size ;                                    /*!< List size*/
00112 } thread_neighbor_class_t;
00113 
00114 typedef struct thread_mcast_child {
00115     uint8_t mac64[8];
00116     ns_list_link_t link;
00117 } thread_mcast_child_t;
00118 
00119 typedef NS_LIST_HEAD (thread_mcast_child_t, link) thread_mcast_children_list_t;
00120 
00121 typedef struct thread_registered_mcast_addr {
00122     uint8_t address[16];
00123     thread_mcast_children_list_t children;
00124     ns_list_link_t link;
00125 } thread_registered_mcast_addr_t;
00126 
00127 typedef NS_LIST_HEAD (thread_registered_mcast_addr_t, link) thread_registered_mcast_addr_list_t;
00128 
00129 typedef struct thread_pending_child_id_req {
00130     uint8_t euid64[8];
00131     uint8_t eiid[8];
00132     uint8_t linkMargin;
00133     uint8_t mode;
00134     uint32_t keySeq;
00135     uint8_t keyId;
00136     bool request_active_config;
00137     uint64_t active_timestamp;
00138     uint64_t pending_timestamp;
00139     uint32_t frameCounter;
00140     uint32_t mleFrameCounter;
00141     uint32_t timeout;
00142     uint16_t version;
00143     bool    shortAddressReq: 1;
00144     bool    networkDataReq: 1;
00145     bool    routeReq: 1;
00146     ns_list_link_t      link;                   /*!< List link entry */
00147 } thread_pending_child_id_req_t;
00148 
00149 typedef NS_LIST_HEAD (thread_pending_child_id_req_t, link) thread_pending_id_req_list_t;
00150 
00151 typedef struct thread_router_id_entry_s {
00152     uint8_t eui64[8];
00153     uint32_t validLifeTime;
00154     bool    reUsePossible;
00155 } thread_router_id_entry_t;
00156 
00157 typedef struct thread_network_data_req_s {
00158     uint8_t request_destination[16];
00159     uint8_t timeout;
00160     bool active;
00161 } thread_network_data_req_t;
00162 
00163 typedef struct thread_leader_info_s {
00164     //DHCPv6 Allocated Router Id's
00165     thread_router_id_entry_t thread_router_id_list[64];
00166     uint8_t leader_id_seq_timer;
00167     uint8_t master_router_id_mask[8];
00168     uint8_t maskSeq;
00169     uint8_t leader_nvm_sync_timer;
00170 } thread_leader_info_t;
00171 
00172 typedef struct thread_leader_data_s {
00173     uint32_t partitionId; //Unique partition ID
00174     uint8_t dataVersion;    //Leader data version number
00175     uint8_t stableDataVersion;  //Leader data stable version number
00176     uint8_t leaderRouterId;   //Leader Router ID
00177     uint8_t weighting;  //Data weighting
00178 } thread_leader_data_t;
00179 
00180 typedef struct thread_connectivity_s {
00181     uint16_t SEDBufferSize;
00182     int8_t  parentPriority;
00183     uint8_t linkQuality3;
00184     uint8_t linkQuality2;
00185     uint8_t linkQuality1;
00186     uint8_t leaderCost;
00187     uint8_t idSequence;
00188     uint8_t activeRouters;
00189     uint8_t SEDDatagramCount;
00190 } thread_connectivity_t;
00191 
00192 typedef struct thread_parent_info_s {
00193     uint8_t mac64[8];
00194     uint16_t shortAddress;
00195     uint16_t version;
00196     uint8_t router_id;
00197     uint8_t pathCostToLeader;
00198     bool    childUpdatePending: 1;
00199     bool    childUpdateProcessActive: 1;
00200 } thread_parent_info_t;
00201 
00202 
00203 typedef struct thread_scanned_parent_s {
00204     thread_leader_data_t leader_data;
00205     uint8_t mac64[8];
00206     uint8_t challengeData[MAX_MLE_CHALLENGE_LENGTH];
00207     uint32_t linLayerFrameCounter;
00208     uint32_t mleFrameCounter;
00209     uint32_t keySequence;
00210     uint16_t shortAddress;
00211     uint8_t chal_len;
00212     uint8_t linkMarginFromParent;
00213     uint8_t linkMarginToParent;
00214     uint8_t security_key_index;
00215     uint8_t routeCostToLeader;
00216     uint8_t linkQuality3;
00217     uint8_t linkQuality2;
00218     uint8_t linkQuality1;
00219     int8_t parentPriority;
00220     uint8_t activeRouters;
00221     uint16_t version;
00222     uint16_t child_id_request_id;
00223 } thread_scanned_parent_t;
00224 
00225 typedef struct thread_ula_prefix_s {
00226     uint8_t     ulaPrefix[8];
00227     bool        ulaValid;
00228 } thread_ula_prefix_t;
00229 
00230 typedef struct thread_master_secret_material_s {
00231     uint8_t     historyKey[32];
00232     uint32_t    keySwitchGuardTimer;
00233     uint32_t    keyRotation;
00234     bool        historyKeyValid: 1;
00235     bool        valid_Info: 1;
00236     uint8_t     historyKeyId;
00237 } thread_master_secret_material_t;
00238 
00239 /*This structure is used for storing active commissioner information*/
00240 typedef struct thread_commissioner {
00241     uint8_t steering_data[16];
00242     uint8_t border_router_address[16];
00243     timeout_t *commissioner_timeout;
00244     char *commissioner_id_ptr;
00245     uint16_t session_id;    /* session_id is valid even if commissioner is not valid */
00246     thread_commissioner_register_status_e commissioner_registration; /* Only for Leader */
00247     uint8_t steering_data_len;
00248     bool commissioner_valid: 1;
00249 } thread_commissioner_t;
00250 
00251 typedef struct thread_announcement_s {
00252     timeout_t *timer;
00253     uint64_t timestamp;
00254     uint16_t channel;
00255     uint16_t panid;
00256     uint8_t channel_page;
00257     uint8_t count;
00258     uint16_t period;
00259     bool announce_success;
00260 } thread_announcement_t;
00261 
00262 typedef struct thread_router_select {
00263     uint8_t routerUpgradeThresHold;
00264     uint8_t routerDowngradeThresHold;
00265     uint8_t possibleDefaultParent;
00266     bool    jitterTimerActive;
00267     uint16_t reedAdvertisementInterval;
00268     uint16_t reedAdvertisementJitterInterval;
00269     timeout_t *reedAdvertisementTimeout;
00270 } thread_router_select_t;
00271 
00272 typedef struct thread_ccm_info {
00273     int8_t coap_service_id;
00274     uint8_t sequence_number;
00275     uint32_t delay_timer;
00276     uint32_t mlr_timer;
00277     timeout_t *reset_timeout;
00278     uint16_t rloc;
00279     uint16_t relay_port_ae;
00280     uint16_t relay_port_nmkp;
00281     int8_t listen_socket_ae;
00282     int8_t listen_socket_nmkp;
00283     bool update_needed: 1;
00284 } thread_ccm_info_t;
00285 
00286 typedef void thread_commission_done_cb(int8_t interface_id);
00287 
00288 typedef struct thread_ccm_credentials {
00289     uint8_t domain_name[16];                        // Thread CCM domain name
00290     uint8_t ccm_addr[16];                           // CCM destination address
00291     const unsigned char *device_certificate_ptr;    // Pointer to CCM device certificate for Autonomous Enrollment
00292     unsigned char *domain_ca_certificate_ptr;       // Pointer to Thread CCM domain CA certificate
00293     unsigned char *domain_certificate_ptr;          // Pointer to Thread CCM domain certificate
00294     unsigned char *domain_pk_ptr;                   // Pointer to Thread domain certificate private key
00295     const unsigned char *device_pk_ptr;             // Pointer to CCM device certificate private key
00296     thread_commission_done_cb *ccm_done_cb;
00297     timeout_t *attach_timeout;
00298 
00299     uint16_t device_certificate_len;                // Device certificate length
00300     uint16_t domain_certificate_len;                // Domain certificate length
00301     uint16_t domain_ca_certificate_len;             // Domain CA certificate length
00302     uint16_t device_pk_len;                         // Device certificate private key length
00303     uint16_t domain_pk_len;                         // Domain certificate private key length
00304     uint16_t ccm_port;                              // CCM destination port
00305 
00306     int8_t coap_service_secure_session_id;
00307     int8_t interface_id;
00308     bool reattach_ongoing;
00309 
00310     ns_list_link_t link;
00311 } thread_ccm_credentials_t;
00312 
00313 typedef struct thread_previous_partition_info_s {
00314     uint32_t partitionId; //partition ID of the previous partition
00315     uint8_t idSequence;   //idSequence last heard from the previous partition
00316     uint8_t weighting;    //weighting last heard from the previous partition
00317 } thread_previous_partition_t;
00318 
00319 
00320 typedef struct thread_info_s {
00321     thread_routing_info_t routing;
00322     thread_neighbor_class_t neighbor_class;
00323     thread_master_secret_material_t masterSecretMaterial;
00324     thread_network_data_cache_entry_t networkDataStorage;
00325     thread_network_local_data_cache_entry_t localServerDataBase;
00326     thread_pending_id_req_list_t childIdReqPending;
00327     thread_commissioner_t registered_commissioner;
00328     thread_ula_prefix_t threadPrivatePrefixInfo;
00329     thread_router_select_t routerSelectParameters;
00330     thread_previous_partition_t previous_partition_info;
00331     thread_leader_info_t *leader_private_data;  //Leader Proxy
00332     thread_parent_info_t *thread_endnode_parent;
00333     thread_leader_data_t *thread_leader_data;  //Dynamic Learned Network Data
00334     thread_scanned_parent_t *thread_attach_scanned_parent;
00335     thread_commissioning_link_configuration_s *native_commissioner_link;
00336     thread_commissioning_native_select_cb *native_commissioner_cb;
00337     thread_network_data_tlv_cb *network_data_tlv_cb;
00338     thread_announcement_t *announcement_info;
00339     thread_ccm_info_t *ccm_info;
00340     thread_ccm_credentials_t *ccm_credentials_ptr;
00341     thread_attach_device_mode_e thread_device_mode;
00342     thread_attach_state_e thread_attached_state; //Indicate Thread stack state
00343     thread_registered_mcast_addr_list_t child_mcast_list;
00344     uint32_t host_link_timeout;
00345     uint32_t sleepy_host_poll_time;
00346     uint32_t testRandomPartitionId;
00347     uint16_t lastAllocatedChildAddress;
00348     uint16_t native_commissioner_port;
00349     uint16_t routerShortAddress;
00350     uint16_t reedJitterTimer;
00351     uint16_t reedMergeAdvTimer;
00352     int16_t childUpdateReqTimer;
00353     uint16_t childUpdateReqMsgId;
00354     uint16_t proactive_an_timer;
00355     uint16_t thread_maintenance_timer;
00356     //uint8_t lastValidRouteMask[8];
00357     int8_t interface_id; //Thread Interface ID
00358     uint8_t version;
00359     uint8_t parent_priority;
00360     uint8_t testMaxActiveRouterIdLimit; //Default for this is 32
00361     uint8_t maxChildCount; //Default for this is 24
00362     uint8_t partition_weighting;
00363     bool rfc6775: 1;
00364     bool requestFullNetworkData: 1;
00365     bool leaderCab: 1;
00366     bool routerIdRequested: 1;
00367     bool releaseRouterId: 1;
00368     bool networkSynch: 1;
00369     bool networkDataRequested: 1;
00370     bool end_device_link_synch: 1;
00371     bool router_mc_addrs_registered: 1;
00372     bool link_sync_allowed: 1;
00373     bool leader_synced: 1; // flag used by leader after restart
00374 } thread_info_t;
00375 
00376 #ifdef HAVE_THREAD
00377 
00378 struct link_configuration;
00379 struct if_group_entry;
00380 
00381 /* Ceil log2 function  Needed to calculate specific values for thread TLVs.
00382  * This is very approximate
00383  */
00384 uint16_t thread_log2_aprx(uint32_t n);
00385 
00386 void thread_anycast_address_policy_update(const thread_info_t *thread_info, bool addPolicy);
00387 
00388 #define thread_info(cur) ((cur)->thread_info)
00389 #define thread_am_reed(cur) ((cur)->thread_info && (cur)->thread_info->thread_attached_state == THREAD_STATE_CONNECTED && (cur)->thread_info->thread_device_mode == THREAD_DEVICE_MODE_ROUTER)
00390 #define thread_am_router(cur) ((cur)->thread_info && (cur)->thread_info->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER && (cur)->thread_info->thread_device_mode == THREAD_DEVICE_MODE_ROUTER)
00391 #define thread_is_connected(cur) ((cur)->thread_info && ((cur)->thread_info->thread_attached_state == THREAD_STATE_CONNECTED || (cur)->thread_info->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER))
00392 #define thread_am_host(cur) ((cur)->thread_info && \
00393         ((cur)->thread_info->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE ||\
00394          (cur)->thread_info->thread_device_mode == THREAD_DEVICE_MODE_END_DEVICE ||\
00395          (cur)->thread_info->thread_device_mode == THREAD_DEVICE_MODE_FULL_END_DEVICE))
00396 
00397 //int thread_configuration_save(thread_info_t *thread_info, link_configuration_s *leader_link_setup);
00398 
00399 bool thread_leader_commissioner_create(thread_info_t *thread_info);
00400 void thread_leader_commissioner_free(thread_info_t *thread_info);
00401 
00402 bool thread_leader_data_parse(uint8_t *ptr, uint16_t dataLength, thread_leader_data_t *leaderDataBuf);
00403 bool thread_connectivity_tlv_parse(uint8_t *ptr, uint16_t dataLength, thread_connectivity_t *connectivityTlv);
00404 
00405 thread_leader_data_t *thread_leader_data_get(thread_info_t *info);
00406 thread_parent_info_t *thread_parent_data_allocate(thread_info_t *info);
00407 void thread_data_base_init(thread_info_t *thread_info, int8_t interfaceId);
00408 int thread_info_allocate_and_init(protocol_interface_info_entry_t *cur);
00409 void thread_info_deallocate(protocol_interface_info_entry_t *cur);
00410 int thread_init(protocol_interface_info_entry_t *cur);
00411 int thread_attach_ready(protocol_interface_info_entry_t *cur);
00412 bool thread_attach_active_router(protocol_interface_info_entry_t *cur);
00413 bool thread_scan_mask_validation(protocol_interface_info_entry_t *cur, uint8_t mask);
00414 int thread_route_ready_to_leader(protocol_interface_info_entry_t *cur);
00415 void thread_timer(protocol_interface_info_entry_t *cur, uint8_t ticks);
00416 void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks);
00417 bool thread_insist_that_mesh_isnt_a_link(const protocol_interface_info_entry_t *cur);
00418 bool thread_addr_is_mesh_local(const uint8_t *addr, const protocol_interface_info_entry_t *cur);
00419 bool thread_on_mesh_route_possible_add(thread_attach_device_mode_e threadMode);
00420 bool thread_addr_is_mesh_local_16(const uint8_t *addr, const protocol_interface_info_entry_t *cur);
00421 uint8_t *thread_addr_write_mesh_local_16(uint8_t ip_addr_out[16], uint16_t addr16, const thread_info_t *thread_info);
00422 int thread_leader_ul16_address_get(thread_info_t *thread_info, uint8_t *address_ptr);
00423 void thread_network_data_request_send(protocol_interface_info_entry_t *cur, uint8_t *requestDstAddress, bool delaydTrig);
00424 uint16_t thread_network_data_generate_stable_set(protocol_interface_info_entry_t *cur, uint8_t *result_ptr);
00425 
00426 void thread_set_active_router(protocol_interface_info_entry_t *cur, if_address_entry_t *address_entry, uint8_t *routerId);
00427 uint8_t thread_get_router_count_from_route_tlv(mle_tlv_info_t *routeTlv);
00428 void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, struct mac_neighbor_table_entry *neighbour);
00429 
00430 void thread_child_id_request_entry_clean(protocol_interface_info_entry_t *cur);
00431 thread_pending_child_id_req_t *thread_child_id_request_entry_get(protocol_interface_info_entry_t *cur, uint8_t *euid64);
00432 void thread_child_id_request_entry_remove(protocol_interface_info_entry_t *cur, thread_pending_child_id_req_t *entry);
00433 thread_pending_child_id_req_t *thread_child_id_request_entry_get_from_the_list(protocol_interface_info_entry_t *cur);
00434 
00435 thread_mcast_child_t *thread_child_mcast_entry_get(protocol_interface_info_entry_t *cur, const uint8_t *mcast_addr, const uint8_t *mac64);
00436 void thread_registered_mcast_addr_entry_clean(protocol_interface_info_entry_t *cur);
00437 thread_registered_mcast_addr_t *thread_registered_mcast_addr_entry_find(protocol_interface_info_entry_t *cur, const uint8_t *mcast_addr);
00438 void thread_child_mcast_entries_remove(protocol_interface_info_entry_t *cur, const uint8_t *mac64);
00439 
00440 uint8_t thread_leader_data_tlv_size(protocol_interface_info_entry_t *cur);
00441 uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
00442 uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
00443 
00444 // returns true if SED/MED needs to register additional address to parent
00445 bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur);
00446 // write mesh local address tlv
00447 uint8_t *thread_ml_address_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
00448 int thread_link_reject_send(protocol_interface_info_entry_t *interface, const uint8_t *ll64);
00449 thread_leader_info_t *thread_allocate_and_init_leader_private_data(void);
00450 thread_route_cost_t thread_link_quality_to_cost(thread_link_quality_e quality);
00451 thread_route_cost_t thread_link_cost_sum(thread_route_cost_t a, thread_route_cost_t b);
00452 thread_link_quality_e thread_link_margin_to_quality(thread_link_margin_t margin);
00453 uint_fast8_t thread_sum_rx_path_cost_and_link_cost(uint8_t inMargim, uint8_t outMargin, uint8_t pathCost);
00454 /*
00455  * Thread beacon payload handling functions
00456  */
00457 int8_t thread_beacon_create_payload(struct protocol_interface_info_entry *cur);
00458 uint8_t thread_beacon_indication(uint8_t *ptr, uint8_t len, protocol_interface_info_entry_t *cur);
00459 
00460 int thread_network_data_propagation(struct protocol_interface_info_entry *cur, uint8_t *childUnicastAddress, bool fullList);
00461 
00462 uint8_t thread_route_option_size(protocol_interface_info_entry_t *cur);
00463 uint8_t *thread_route_option_write(protocol_interface_info_entry_t *cur, uint8_t *ptr);
00464 
00465 /*Generic Thread TLV write*/
00466 uint8_t *thread_connectivity_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur, uint8_t mode);
00467 
00468 /*Network data TLV write*/
00469 uint16_t thread_network_data_tlv_size(struct protocol_interface_info_entry *cur, bool fulllist);
00470 uint8_t *thread_network_data_tlv_write(struct protocol_interface_info_entry *cur, uint8_t *ptr, bool fulllist);
00471 
00472 /* Active and pending operational dataset write*/
00473 uint8_t *thread_active_timestamp_write(protocol_interface_info_entry_t *cur, uint8_t *ptr);
00474 uint16_t thread_active_operational_dataset_size(protocol_interface_info_entry_t *cur);
00475 uint8_t *thread_active_operational_dataset_write(protocol_interface_info_entry_t *cur, uint8_t *ptr);
00476 bool thread_active_operational_dataset_process(protocol_interface_info_entry_t *cur, uint8_t *ptr, uint16_t len, uint64_t dataset_timestamp);
00477 uint8_t *thread_pending_timestamp_write(protocol_interface_info_entry_t *cur, uint8_t *ptr);
00478 uint16_t thread_pending_operational_dataset_size(protocol_interface_info_entry_t *cur);
00479 uint8_t *thread_pending_operational_dataset_write(protocol_interface_info_entry_t *cur, uint8_t *ptr);
00480 bool thread_pending_operational_dataset_process(protocol_interface_info_entry_t *cur, uint64_t mle_pending_timestamp, uint8_t *ptr, uint16_t len);
00481 /*Write optional thread leader data TLV if leader data is known*/
00482 uint8_t thread_pending_timestamp_tlv_size(protocol_interface_info_entry_t *cur);
00483 void thread_key_guard_timer_calculate(protocol_interface_info_entry_t *cur, link_configuration_s *linkConfiguration, bool is_init);
00484 void thread_key_guard_timer_reset(protocol_interface_info_entry_t *cur);
00485 void thread_set_link_local_address(protocol_interface_info_entry_t *cur);
00486 void thread_mcast_group_change(struct protocol_interface_info_entry *interface, struct if_group_entry *group, bool group_added);
00487 void thread_partition_data_purge(protocol_interface_info_entry_t *cur);
00488 bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
00489 void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
00490 void thread_neighbor_communication_update(protocol_interface_info_entry_t *cur, uint8_t neighbor_attribute_index);
00491 bool thread_stable_context_check(protocol_interface_info_entry_t *cur, buffer_t *buf);
00492 void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur);
00493 
00494 #ifdef HAVE_THREAD_V2
00495 void thread_common_ccm_allocate(protocol_interface_info_entry_t *cur);
00496 void thread_common_ccm_free(protocol_interface_info_entry_t *cur);
00497 bool thread_common_ccm_enabled(protocol_interface_info_entry_t *cur);
00498 int thread_common_primary_bbr_get(struct protocol_interface_info_entry *cur, uint8_t *addr_ptr, uint8_t *seq_ptr, uint32_t *mlr_timer_ptr, uint32_t *delay_timer_ptr);
00499 #else
00500 #define thread_common_ccm_allocate(cur)
00501 #define thread_common_ccm_free(cur)
00502 #define thread_common_ccm_enabled(cur) (false)
00503 #define thread_common_primary_bbr_get(cur, addr_ptr, seq_ptr, mlr_timer_ptr, delay_timer_ptr) (0)
00504 
00505 #endif
00506 #else // HAVE_THREAD
00507 
00508 NS_DUMMY_DEFINITIONS_OK
00509 #define thread_stable_context_check(cur, buf) (false)
00510 #define thread_info(cur) ((thread_info_t *) NULL)
00511 #define thread_am_router(cur) (false)
00512 #define thread_am_host(cur) (false)
00513 
00514 #define thread_addr_is_mesh_local(addr, cur) false
00515 #define thread_addr_is_mesh_local_16(addr, cur) false
00516 #define thread_timer(cur, ticks) ((void) 0)
00517 #define thread_seconds_timer(cur, ticks) ((void) 0)
00518 #define thread_insist_that_mesh_isnt_a_link(cur) false
00519 #define thread_attach_ready(cur) 0
00520 #define thread_info_allocate_and_init(cur) (-1)
00521 #define thread_info_deallocate(cur) ((void)0)
00522 #define thread_network_data_propagation(cur, childUnicastAddress, fullList) (void(-1))
00523 #define thread_link_reject_send(interface, ll64) 0
00524 #define thread_addr_is_mesh_local_16(addr, cur) false
00525 #define thread_mcast_group_change(interface, group, group_added) ((void)0)
00526 #define thread_neighbor_communication_update(cur, neighbor_attribute_index) ((void)0)
00527 #endif // HAVE_THREAD
00528 
00529 #endif /* LOWPAN_THREAD_H_ */