BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mle.h Source File

mle.h

00001 /*
00002  * Copyright (c) 2013-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef MLE_H_
00019 #define MLE_H_
00020 
00021 #include "nsconfig.h"
00022 #include "Core/include/address.h"
00023 #include "ns_list.h"
00024 
00025 struct buffer;
00026 
00027 #ifndef MAX_MLE_INFO_CNT
00028 #ifdef CORTEXM3_STM32W108CC
00029 #define MAX_MLE_INFO_CNT 40
00030 #else
00031 #define MAX_MLE_INFO_CNT 256
00032 #endif
00033 #endif
00034 
00035 #define MLE_MAX_ROUTERS 64
00036 /* Route option layout: 1 Sequence byte, ID mask (bit per router), Data (byte per valid ID) */
00037 #define MLE_ROUTE_ID_MASK_SIZE   ((MLE_MAX_ROUTERS+7)/8)
00038 #define MLE_ROUTE_MAX_DATA_SIZE  MLE_MAX_ROUTERS
00039 #define MLE_ROUTE_MIN_OPTION_LEN (1 + MLE_ROUTE_ID_MASK_SIZE)
00040 
00041 /* MLE messge types */
00042 #define MLE_COMMAND_REQUEST                 0
00043 #define MLE_COMMAND_ACCEPT                  1
00044 #define MLE_COMMAND_ACCEPT_AND_REQUEST      2
00045 #define MLE_COMMAND_REJECT                  3
00046 #define MLE_COMMAND_ADVERTISEMENT           4
00047 #define MLE_COMMAND_UPDATE                  5
00048 #define MLE_COMMAND_UPDATE_REQUEST          6
00049 /* New messages for Thread */
00050 #define MLE_COMMAND_DATA_REQUEST            7
00051 #define MLE_COMMAND_DATA_RESPONSE           8
00052 #define MLE_COMMAND_PARENT_REQUEST          9  //Old MLE attache message number 1
00053 #define MLE_COMMAND_PARENT_RESPONSE        10  //Old MLE attache message number 2
00054 #define MLE_COMMAND_CHILD_ID_REQUEST       11  //Old MLE attache message number 3
00055 #define MLE_COMMAND_CHILD_ID_RESPONSE      12  //Old MLE attache message number 4
00056 #define MLE_COMMAND_CHILD_UPDATE_REQUEST   13
00057 #define MLE_COMMAND_CHILD_UPDATE_RESPONSE  14
00058 #define MLE_COMMAND_DATASET_ANNOUNCE       15
00059 #define MLE_COMMAND_DISCOVERY_REQUEST      16
00060 #define MLE_COMMAND_DISCOVERY_RESPONSE     17
00061 #define MLE_COMMAND_METRIC_MANAGEMENT_REQUEST            18 // Experimental for BH
00062 #define MLE_COMMAND_METRIC_MANAGEMENT_RESPONSE           19 // Experimental for BH
00063 #define MLE_COMMAND_PROBE                                20 // Experimental for BH
00064 
00065 #define MLE_UPDATE_CHANNEL          0
00066 #define MLE_UPDATE_PAN_ID             1
00067 #define MLE_UPDATE_PERMIT_MSG         2
00068 #define MLE_UPDATE_BEACON_PAYLOAD   3
00069 
00070 #define MLE_UPDATE_CHANNEL_FLAG          (1 << 0)
00071 #define MLE_UPDATE_PAN_ID_FLAG           (1 << 1)
00072 #define MLE_UPDATE_PERMIT_MSG_FLAG       (1 << 2)
00073 #define MLE_UPDATE_BEACON_PAYLOAD_FLAG (1 << 3)
00074 
00075 #define MLE_UPDATE_PROCESS_TRIG         0x80
00076 
00077 #define MLE_ERROR_NO_ERROR            0
00078 #define MLE_ERROR_BUFFER_ERROR        1
00079 #define MLE_ERROR_ADDRESS_ERROR       2
00080 #define MLE_ERROR_WRONG_TYPE          3
00081 #define MLE_ERROR_ALLOCATION_ERROR    4
00082 #define MLE_ERROR_DATA_TOO_LONG       5
00083 #define MLE_ERROR_UNSUPPORTED_TYPE    6
00084 #define MLE_ERROR_RESPONSE_NOT_WAITED 7
00085 
00086 #define MLE_CHALLENGE_SIZE 4
00087 #define MLE_RESPONSE_SIZE  32
00088 #define MLE_MAX_SIZE       116
00089 
00090 /* MLE TLV types */
00091 typedef enum mle_tlv_type_t_ {
00092     /* draft-kelsey-intarea-mesh-link-establishment-06 */
00093     MLE_TYPE_SRC_ADDRESS = 0,
00094     MLE_TYPE_MODE = 1,
00095     MLE_TYPE_TIMEOUT = 2,
00096     MLE_TYPE_CHALLENGE = 3,
00097     MLE_TYPE_RESPONSE = 4,
00098     MLE_TYPE_LL_FRAME_COUNTER = 5,
00099     MLE_TYPE_LINK_QUALITY = 6,
00100     MLE_TYPE_NWK_PARAM = 7,
00101     MLE_TYPE_MLE_FRAME_COUNTER = 8,
00102     /* Thread MLE Extensions (draft-kelsey-thread-mle-01) */
00103     MLE_TYPE_ROUTE = 9,
00104     MLE_TYPE_ADDRESS16 = 10,
00105     MLE_TYPE_LEADER_DATA = 11,
00106     MLE_TYPE_NETWORK_DATA = 12,
00107     MLE_TYPE_TLV_REQUEST = 13,
00108     MLE_TYPE_SCAN_MASK = 14,
00109     MLE_TYPE_CONNECTIVITY = 15,
00110     MLE_TYPE_RSSI = 16,
00111     MLE_TYPE_STATUS = 17,
00112     MLE_TYPE_VERSION = 18,
00113     MLE_TYPE_ADDRESS_REGISTRATION = 19,
00114     MLE_TYPE_CHANNEL = 20,
00115     MLE_TYPE_PANID = 21,
00116     MLE_TYPE_ACTIVE_TIMESTAMP = 22,
00117     MLE_TYPE_PENDING_TIMESTAMP = 23,
00118     MLE_TYPE_OPERATIONAL_DATASET = 24,
00119     MLE_TYPE_PENDING_OPERATIONAL_DATASET = 25,
00120     MLE_TYPE_DISCOVERY = 26,
00121     /* Thread low power TLVs*/
00122     MLE_TYPE_LINK_METRICS_QUERY = 87,
00123     MLE_TYPE_LINK_METRICS_MANAGEMENT = 88,
00124     MLE_TYPE_LINK_METRICS_REPORT = 89,
00125     MLE_TYPE_UNASSIGNED = 0xFF
00126 } mle_tlv_type_t;
00127 
00128 #define MLE_STATUS_ERROR 1
00129 /* MLE Mode = IEEE 802.15.4 Capability Information */
00130 #define MLE_DEV_MASK 2
00131 #define MLE_FFD_DEV 2
00132 #define MLE_RFD_DEV 0
00133 #define MLE_RX_ON_IDLE 8
00134 /** Thead Spesific ModeFlags */
00135 #define MLE_THREAD_SECURED_DATA_REQUEST 0x04
00136 #define MLE_THREAD_REQ_FULL_DATA_SET 0x01
00137 
00138 #define MLE_TIMER_TICKS_SECONDS     4
00139 #define MLE_TIMER_TICKS_MS (MLE_TIMER_TICKS_SECONDS*1000)
00140 
00141 #define MLE_TABLE_CHALLENGE_TIMER       3
00142 
00143 #define MLE_NEIGHBOR_PRIORITY_LINK (1 << 5)
00144 #define MLE_NEIGHBOR_OUTGOING_LINK (1 << 6)
00145 #define MLE_NEIGHBOR_INCOMING_LINK (1 << 7)
00146 
00147 typedef struct mle_neigh_table_entry_t {
00148     uint8_t                             attribute_index;
00149     uint16_t                           ttl;                       /*!< destination TTL * 4 seconds */
00150     uint32_t                            last_contact_time;        /*!< monotonic time - hard to define "contact"; used for Thread Leasequery replies */
00151     uint32_t                           mle_frame_counter;
00152     uint16_t                           timeout_rx;
00153     uint16_t                            holdTime;
00154     uint16_t                            link_margin;
00155     uint8_t                            mac64[8];                  /*!< MAC64 */
00156     uint8_t                            mlEid[8];
00157     uint16_t                           short_adr;
00158     uint8_t                            mode;
00159     uint16_t                           etx;                       /*!< 12 bits fraction */
00160     uint16_t                           stored_diff_etx;           /*!< 12 bits fraction */
00161     uint8_t                            remote_incoming_idr;       /*!< 5 bits fraction */
00162     uint32_t                           last_key_sequence;
00163     unsigned                           accumulated_failures: 5;
00164     unsigned                           new_key_pending:1;
00165     unsigned                           link_q_adv_sent: 1;
00166     unsigned                           tmp_etx: 1;
00167     unsigned                           priority_child_flag: 1;    /* Is using our node as preferred parent */
00168     unsigned                           second_priority_flag: 1;   /* Is secondary parent */
00169     unsigned                            thread_commission: 1;
00170     unsigned                           threadNeighbor: 1;
00171     unsigned                            priorityFlag: 1;
00172     unsigned                            handshakeReady: 1;
00173     unsigned                            medium_ttl_challenge: 1;
00174     unsigned                            linkIdr: 4;
00175     ns_list_link_t                     link;
00176 } mle_neigh_table_entry_t ;
00177 
00178 typedef NS_LIST_HEAD (mle_neigh_table_entry_t, link) mle_neigh_table_list_t;
00179 
00180 
00181 /* MLE TLV types */
00182 typedef enum mle_class_user_mode {
00183     MLE_CLASS_ROUTER = 0,
00184     MLE_CLASS_END_DEVICE,
00185     MLE_CLASS_SLEEPY_END_DEVICE,
00186 } mle_class_user_mode;
00187 
00188 //MLE table class function pointer types
00189 /**
00190  * Remove entry notify
00191  */
00192 typedef void mle_entry_user_entry_remove_notify(int8_t interface_id, mle_neigh_table_entry_t *entry_ptr);
00193 
00194 typedef int8_t mle_entry_link_keep_alive(int8_t interface_id, const uint8_t *mac64);
00195 
00196 typedef bool mle_entry_interface_activate(int8_t interface_id);
00197 
00198 int8_t mle_class_init(int8_t interface_id, uint8_t table_size, mle_entry_user_entry_remove_notify *remove_cb, mle_entry_link_keep_alive *keep_alive_cb, mle_entry_interface_activate *interface_is_active);
00199 
00200 int8_t mle_class_router_challenge(int8_t interface_id,mle_entry_link_keep_alive *challenge_cb);
00201 
00202 bool mle_class_exists_for_interface(int8_t interface_id);
00203 
00204 int8_t mle_class_deallocate(int8_t interface_id);
00205 
00206 int8_t mle_class_list_clean(int8_t interface_id);
00207 
00208 int8_t mle_class_mode_set(int8_t interface_id,mle_class_user_mode mode);
00209 
00210 int8_t mle_class_set_new_key_pending(int8_t interface_id);
00211 
00212 int16_t mle_class_free_entry_count_get(int8_t interface_id);
00213 
00214 mle_neigh_table_entry_t *mle_class_get_entry_by_ll64(int8_t interface_id, uint8_t linkMargin, const uint8_t *ipv6Address, bool allocateNew);
00215 
00216 mle_neigh_table_entry_t *mle_class_discover_entry_by_ll64(int8_t interface_id, const uint8_t *ipv6Address);
00217 
00218 mle_neigh_table_entry_t *mle_class_get_entry_by_mac64(int8_t interface_id, uint8_t linkMargin, const uint8_t *mac64, bool allocateNew);
00219 
00220 mle_neigh_table_entry_t *mle_class_get_by_link_address(int8_t interface_id, const uint8_t *address, addrtype_t type);
00221 
00222 mle_neigh_table_entry_t *mle_class_get_by_device_attribute_id(int8_t interface_id, uint8_t attribute_index);
00223 
00224 int8_t mle_class_remove_entry(int8_t interface_id, mle_neigh_table_entry_t *entry);
00225 
00226 int8_t mle_class_remove_neighbour(int8_t interface_id, const uint8_t *address, addrtype_t type);
00227 
00228 mle_neigh_table_list_t *mle_class_active_list_get(int8_t interface_id);
00229 
00230 int16_t mle_class_sleepy_entry_count_get(int8_t interface_id);
00231 int16_t mle_class_rfd_entry_count_get(int8_t interface_id);
00232 
00233 uint16_t mle_class_active_neigh_counter(int8_t interface_id);
00234 
00235 /**
00236  *  Function to refresh Neigh Entry when get some trusted response or spesified place
00237  */
00238 mle_neigh_table_entry_t *mle_refresh_entry_timeout(int8_t interfaceId, const uint8_t *addressPtr, addrtype_t addressType, bool dataPollConfirmation);
00239 
00240 bool mle_neigh_entry_frame_counter_update(mle_neigh_table_entry_t *entry_temp, uint8_t *tlv_ptr, uint16_t tlv_length, struct protocol_interface_info_entry *cur, uint8_t key_id);
00241 
00242 uint8_t *mle_general_write_source_address(uint8_t *ptr, struct protocol_interface_info_entry *cur);
00243 
00244 uint8_t *mle_general_write_link_layer_framecounter(uint8_t *ptr, struct protocol_interface_info_entry *cur);
00245 void mle_entry_timeout_update(mle_neigh_table_entry_t *entry_temp, uint32_t timeout_tlv);
00246 void mle_entry_timeout_refresh(mle_neigh_table_entry_t *entry_temp);
00247 
00248 #endif /* MLE_H_ */