takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers net_thread_test.h Source File

net_thread_test.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2018, 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 
00030 #ifndef NET_THREAD_TEST_H_
00031 #define NET_THREAD_TEST_H_
00032 
00033 /* Prevent this file being inserted in public Doxygen generated file
00034  * this is not part of our external API. */
00035 #ifndef DOXYGEN
00036 
00037 /**
00038  * \file net_thread_test.h
00039  * \brief Thread Library Test API.
00040  *
00041  * \warning NOTICE! This is test API must not be used externally.
00042  *
00043  * \warning This file is not part of the version number control and can change any time.
00044  *
00045  */
00046 
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 #include "ns_types.h"
00053 
00054 #define thread_test_router_upgrade(iface) thread_test_router_id_request_send(iface, 2) // THREAD_COAP_STATUS_TLV_TOO_FEW_ROUTERS
00055 /**
00056   * \brief Add a static neighbour
00057   *
00058   * Test API: Add a neighbour. Adds, or updates, a non-expiring neighbour to the
00059   * Thread Link Set, and updates the Route Set accordingly. Basically equivalent
00060   * to receiving an MLE advertisement with a Route TLV, except it doesn't expire.
00061   *
00062   * See draft-kelsey-thread-routing-00 for more info on data format.
00063   *
00064   * \param interface_id Interface to modify
00065   * \param neighbour_addr Neighbour short address (must be a router address)
00066   * \param link_margin_db Notional link margin for reception from this neighbour.
00067   * \param id_sequence Sequence number for id_mask
00068   * \param id_mask Bit mask of router IDs
00069   * \param route_data One octet per set bit in id_mask
00070   *
00071   * \return  0 Success
00072   * \return <0 Failure
00073   */
00074 int_fast8_t arm_nwk_6lowpan_thread_test_add_neighbour(
00075     int8_t interface_id,
00076     uint16_t neighbour_short_addr,
00077     uint_fast8_t link_margin_db,
00078     uint8_t id_sequence,
00079     const uint8_t *id_mask,
00080     const uint8_t *route_data);
00081 
00082 /**
00083  * \brief API to set reed advertisement interval
00084  * \param interface_id Interface to modify
00085  * \param advertisement_interval Interval between advertisements to be set
00086  * \param jitter_interval Maximum value of random jitter interval to be added to advertisement_interval
00087  * \return   0 Success
00088  * \return < 0 Other errors
00089  */
00090 int8_t thread_reed_set_advertisement_interval(int8_t interface_id, uint16_t advertisement_interval, uint16_t jitter_interval);
00091 
00092 /**
00093   * \brief Remove a static neighbour
00094   *
00095   * Test API: Remove a neighbour. Remove a neighbour from the Thread Link Set
00096   * (whether added through arm_nwk_6lowpan_thread_test_add_neighbour, or
00097   * automatically through MLE).
00098   *
00099   * \param interface_id Interface to modify
00100   * \param neighbour_addr Neighbour short address (must be a router address)
00101   *
00102   * \return  0 Success
00103   * \return -1 Not an existing neighbour
00104   * \return <-1 Other errors
00105   */
00106 int_fast8_t arm_nwk_6lowpan_thread_test_remove_neighbour(
00107     int8_t interface_id,
00108     uint16_t neighbour_short_addr);
00109 
00110 /**
00111   * \brief Print routing database
00112   *
00113   * Test API: Dump the routing data base (Router ID Set, Link Set and Route
00114   * Set) to the debug channel.
00115   *
00116   * \param interface_id Interface to interrogate
00117   */
00118 void arm_nwk_6lowpan_thread_test_print_routing_database(int8_t interface_id);
00119 
00120 
00121 /**
00122  * \brief Thread Leader max router ID limit set
00123  *
00124  * This function should use just for test purpose Thread define this by default to 32
00125  *
00126  * \param interface_id Network Interface
00127  * \param maxRouterLimit Min Accepted value is 1 and max 32
00128  *
00129  * return 0, Set OK
00130  * return <0 Set Fail
00131  */
00132 int thread_test_max_accepted_router_id_limit_set(
00133     int8_t interface_id,
00134     uint8_t maxRouterLimit);
00135 
00136 /**
00137   * \brief Set Thread network ID timeout
00138   *
00139   * \param interface_id Interface to modify
00140   * \param network_id_timeout network timeout as seconds
00141   *
00142   * \return  0 Success
00143   * \return -1 Invalid interface id
00144   * \return -2 Thread not active
00145   * \return -3 invalid timeout value
00146   */
00147 int8_t thread_routing_set_network_id_timeout(int8_t interface_id, uint16_t network_id_timeout);
00148 
00149 /**
00150   * \brief Get Thread network ID timeout
00151   *
00152   * \param interface_id Interface to modify
00153   * \param network_id_timeout pointer, where current network id timeout will be saved as seconds
00154   *
00155   * \return  0 Success
00156   * \return -1 Invalid interface id
00157   * \return -2 Thread not active
00158   * \return -3 invalid pointer
00159   */
00160 int8_t thread_routing_get_network_id_timeout(int8_t interface_id, uint16_t *network_id_timeout);
00161 
00162 /**
00163  * \brief Print Thread network data
00164  *
00165  * \param interface_id Network Interface
00166  *
00167  * \return 0, OK
00168  * \return <0 Not OK
00169  */
00170 
00171 int thread_test_print_network_data(int8_t interface_id);
00172 
00173 /**
00174  * \brief Thread Leader Context ID reuse timeout set
00175  *
00176  * This function should be used to change default 48 hours to shorter one
00177  *
00178  * \param interface_id Network Interface
00179  * \param timeout Min Accepted value is 60 seconds and max  48 hours (48*3600)
00180  *
00181  * \return 0, Set OK
00182  * \return <0 Set Fail
00183  */
00184 int thread_test_set_context_id_reuse_timeout(
00185     int8_t interface_id,
00186     uint32_t timeout);
00187 
00188 /**
00189  * \brief Leader of Thread network can kick Router out from Network.
00190  *
00191  * \param interface_id Network Interface
00192  * \param routerId Routter id of router that is kicked
00193  *
00194  * \return 0, Remove OK
00195  * \return <0 Remove fail
00196  */
00197 int thread_test_remove_router_by_id(int8_t interface_id, uint8_t routerId);
00198 
00199 /**
00200  * \brief Start router downgrade process.
00201  *
00202  * \param interface_id Network Interface
00203  *
00204  * \return 0, downgrade started
00205  * \return <0 fail
00206  */
00207 int thread_test_router_downgrade(int8_t interface_id);
00208 
00209 /**
00210  * \brief Set Thread Security Material. Terms are defined in Thread security specification
00211  *
00212  * \param interface_id Network Interface
00213  * \param enableSecurity Boolean for enable security or disable
00214  * \param thrMasterKey Master Key material which will be used for generating new key
00215  * \param thrKeySequenceCounter Periodic counter used to generate new MAC and MLE keys
00216  * \param thrKeyRotation Update period (in seconds) for thrKeySequenceCounter
00217  *
00218  * \return 0, ADD OK
00219  * \return <0 Add Not OK
00220  */
00221 int thread_test_security_material_set(int8_t interface_id, bool enableSecurity, uint8_t *thrMasterKey, uint32_t thrKeySequenceCounter, uint32_t thrKeyRotation);
00222 
00223 /**
00224  * \brief Set Thread version number.
00225  *
00226  * \param interface_id Network Interface
00227  * \param version "1 == Thread version 1.0" or "2 == Thread version 1.1"
00228  *
00229  * \return 0, OK
00230  * \return <0 Error
00231  */
00232 int thread_test_version_set(int8_t interface_id, uint8_t version);
00233 /**
00234  * \brief Set Thread router selection jitter.
00235  *
00236  * \param interface_id Network Interface
00237  * \param value must be over 1 default is 120
00238  *
00239  * \return 0, OK
00240  * \return <0 Error
00241  */
00242 int thread_test_router_selection_jitter_set(int8_t interface_id, uint32_t jitter);
00243 
00244 /**
00245  * \brief Sets the thread MIN_DELAY_TIMER default value.
00246  *
00247  * \param interface_id Network Interface
00248  * \param delay_timer_value delay timer value in seconds used in leader
00249  *
00250  * \return 0, OK
00251  * \return <0 Error
00252  */
00253 int thread_test_min_delay_timer_set(int8_t interface_id, uint32_t delay_timer_value);
00254 /**
00255  * \brief Increment Thread key sequence counter
00256  *
00257  * \param interface_id Network Interface
00258  *
00259  * \return 0, OK
00260  * \return <0 Error
00261  */
00262 int thread_test_increment_key_sequence_counter(int8_t interface_id);
00263 
00264 /**
00265  * \brief Set new Thread key sequence counter
00266  *
00267  * Call define new key and next key same time
00268  *
00269  * \param interface_id Network Interface
00270  * \param thrKeySequenceCounter this need to be bigger than current sequence
00271  *
00272  * \return 0, OK
00273  * \return <0 Error
00274  */
00275 int thread_test_key_sequence_counter_update(int8_t interface_id, uint32_t thrKeySequenceCounter);
00276 
00277 /**
00278  * \brief Resets cached values from stack
00279  *
00280  Resets link configuration from cache and from  NVM.
00281  *
00282   *
00283  * \param interface_id Network Interface
00284   *
00285  * \return 0, OK
00286  * \return <0 Error
00287  */
00288 int thread_test_stack_cache_reset(int8_t interface_id);
00289 
00290 /**
00291  * \brief Set new Thread key rotation value
00292  *
00293  * \param interface_id Network interface ID
00294  * \param thrKeyRotation Key rotation value in seconds
00295  *
00296  * \return 0, OK
00297  * \return <0 Error
00298  */
00299 int thread_test_key_rotation_update(int8_t interface_id, uint32_t thrKeyRotation);
00300 
00301 /**
00302  * \brief Thread router select threshold values set
00303  *
00304  * \param interface_id Network Interface
00305  * \param upgradeThreshold Set REED up grade to router threshold
00306  * \param downgradeThreshold Set Router down grade to REED threshold
00307  *
00308  * \return 0, Set OK
00309  * \return <0 Set Fail
00310  */
00311 int thread_test_router_select_threshold_values_set(
00312     int8_t interface_id,
00313     uint8_t upgradeThreshold,
00314     uint8_t downgradeThreshold);
00315 
00316 /**
00317  * \brief Send PAN ID query message to destination
00318  *
00319  * \param interface_id Network Interface
00320  *
00321  * \return 0, Set OK
00322  * \return <0 Set Fail
00323  */
00324 int thread_test_panid_query_send(int8_t interface_id, uint8_t *address_ptr, uint16_t session_id, uint16_t panid, uint8_t channel_page, uint8_t *mask_ptr);
00325 
00326 /**
00327  * \brief Send energy scan message to destination
00328  *
00329  * \param interface_id Network Interface
00330  *
00331  * \return 0, Set OK
00332  * \return <0 Set Fail
00333  */
00334 int thread_test_energy_scan_send(int8_t interface_id, uint8_t *address_ptr, uint16_t session_id, uint8_t channel_page, uint8_t *mask_ptr, uint16_t period, uint8_t count, uint16_t duration);
00335 
00336 /**
00337  * \brief Send announcement message
00338  *
00339  * \param interface_id Network Interface
00340  * \param channel high uint16 is the channel page, lower part is the channel number on that page
00341  *
00342  * \return 0, Set OK
00343  * \return <0 Set Fail
00344  */
00345 int thread_test_announce_ntf_send(int8_t interface_id, uint8_t *address_ptr, uint32_t channel, uint16_t panid, uint64_t timestamp);
00346 
00347 /**
00348  * \brief Send energy scan message to destination
00349  *
00350  * \param interface_id Network Interface
00351  *
00352  * \return 0, Set OK
00353  * \return <0 Set Fail
00354  */
00355 int thread_test_announce_begin_send(int8_t interface_id, uint8_t *address_ptr, uint16_t session_id, uint8_t channel_page, uint8_t *mask_ptr, uint16_t period, uint8_t count);
00356 
00357 /**
00358  * \brief Get partition info
00359  *
00360  * \param interface_id Network Interface
00361  * \param partition_id Current partition id can be NULL if not needed.
00362  * \param weighting Current weighting can be NULL if not needed.
00363  * \param data_version Current data version can be NULL if not needed.
00364  * \param stable_data_version Current stable data version can be NULL if not needed.
00365  * \param leader_id Current leader id can be NULL if not needed.
00366  *
00367  * \return 0, Set OK
00368  * \return <0 Set Fail
00369  */
00370 int thread_test_partition_info_get(int8_t interface_id, uint32_t *partition_id, uint8_t *weighting, uint8_t *data_version, uint8_t *stable_data_version, uint8_t *leader_id);
00371 
00372 /**
00373  * \brief Set next partition ID when we next time partition. This is used to control specific behaviour in tests.
00374  *
00375  * \param interface_id Network Interface
00376  *
00377  * \return 0, Set OK
00378  * \return <0 Set Fail
00379  */
00380 int thread_test_partition_info_set(int8_t interface_id, uint32_t partition_id);
00381 
00382 /**
00383  * \brief Get thread information.
00384  *
00385  * \param interface_id Network Interface
00386  * \param short_addr own short address
00387  * \param router_count amount of active routers in network
00388  * \param network_stable stable network achieved no upgrade or downgrade pending
00389  *
00390  * \return 0, Set OK
00391  * \return <0 Set Fail
00392  */
00393 int8_t thread_test_thread_information_get(int8_t interface_id, uint16_t *short_addr, uint8_t *router_count, bool *network_stable);
00394 
00395 /**
00396  * \brief Get child count
00397  *
00398  * \param interface_id Network Interface
00399  *
00400  * \return 0, Set OK
00401  * \return <0 Set Fail
00402  */
00403 int8_t thread_test_child_count_get(int8_t interface_id);
00404 
00405 /**
00406  * \brief Get child information
00407  *
00408  * get information for index child. if found returns 0 with correct information.
00409  *
00410  * \param interface_id Network Interface
00411  *
00412  * \return 0, OK
00413  * \return <0 Fail no child with this index found
00414  */
00415 int8_t thread_test_child_info_get(int8_t interface_id, uint8_t index, uint16_t *short_addr, bool *sleepy, uint8_t *mac64, uint8_t *margin);
00416 
00417 /**
00418  * \brief Get neighbour information
00419  *
00420  * \param interface_id Network Interface
00421  *
00422  * \return 0, Set OK
00423  * \return <0 Set Fail
00424  */
00425 int8_t thread_test_neighbour_info_get(int8_t interface_id, uint8_t index, uint16_t *short_addr, uint8_t *mac64, uint8_t *margin);
00426 
00427 typedef int (response_cb)(int8_t interface_id, uint8_t *response_ptr, uint16_t response_len);
00428 
00429 /**
00430  * \brief Send diagnostic command DEPRECATED
00431  *
00432  * \param interface_id      Network Interface
00433  * \param address_ptr       Address to which the command is sent
00434  * \param uri_ptr           Uri for the command
00435  * \param request_length    The length of the request
00436  * \param request_ptr       Pointer to the beginning of the request contents
00437  * \param resp_cb           Pointer to callback function that is called after the reply for the command is obtained
00438  * \return 0,               Command send OK
00439  * \return <0               Command send Fail
00440  */
00441 int thread_test_diagnostic_command_send(int8_t interface_id, uint8_t *address_ptr,const char *uri_ptr, uint8_t request_length, uint8_t *request_ptr, response_cb *resp_cb);
00442 
00443 typedef int (coap_response_cb)(int8_t interface_id, uint8_t message_code, uint8_t message_type, uint8_t *response_ptr, uint16_t response_len);
00444 
00445 /**
00446  * \brief Send diagnostic request
00447  *
00448  * \param interface_id      Network Interface
00449  * \param address_ptr       Address to which the command is sent
00450  * \param msg_type           Uri for the command
00451  * \param msg_code           Uri for the command
00452  * \param uri_ptr           Uri for the command
00453  * \param request_length    The length of the request
00454  * \param request_ptr       Pointer to the beginning of the request contents
00455  * \param resp_cb           Pointer to callback function that is called after the reply for the command is obtained
00456  *
00457  * \return 0,               Command send OK
00458  * \return <0               Command send Fail
00459  */
00460 int thread_test_coap_request_send(int8_t interface_id, uint8_t *address_ptr, uint16_t port, uint8_t msg_type, uint8_t msg_code, uint16_t content_format, const char *uri_ptr, uint8_t *request_ptr, uint8_t request_length, coap_response_cb *resp_cb);
00461 
00462 /**
00463  * \brief Set initial SLAAC iid.
00464  *
00465  * \param interface_id      Network Interface
00466  * \param iid               Interface identifier pointer must be 8 bytes long buffer. can be NULL to disable.
00467  * \return 0,               Command OK
00468  * \return <0               Command Fail
00469  */
00470 int8_t thread_test_initial_slaac_iid_set(int8_t interface_id, uint8_t *iid);
00471 
00472 /**
00473  * \brief Send router ID request.
00474  *
00475  * \param interface_id      Network Interface
00476  * \param status            Value of router ID request status TLV
00477  * \return 0,               Command OK
00478  * \return <0               Command Fail
00479  */
00480 int8_t thread_test_router_id_request_send(int8_t interface_id, uint8_t status);
00481 
00482 /**
00483  * \brief Set joiner port to joiner router device.
00484  * If port == 0, then default port is used.
00485  *
00486  * \param iid               Joiner port.
00487  * \return 0,               Command OK
00488  * \return <0               Command Fail
00489  */
00490 int8_t thread_test_joiner_router_joiner_port_set(uint16_t port);
00491 
00492 /**
00493  *\brief set a router address to be requested. For a router, this address is sent
00494  *\in address solicit request to leader and for leader this is the router address
00495  *
00496  * \param interface_id               Network Interface
00497  * \param router_addr                Address requested
00498  * \return 0,                        Command OK
00499  * \return <0                        Command Fail
00500  */
00501 int8_t thread_test_router_address_set(int8_t interface_id, uint16_t router_addr);
00502 
00503 /**
00504  *\brief sends any MLE message to any destination.
00505  *
00506  * \param interface_id               Network Interface
00507  * \param dst_address                destination address
00508  * \param msg_id                     MLE message id
00509  * \param write_src_addr             write short address of the device
00510  * \param write_leader_data          write leader data
00511  * \param write_network_data         write network data
00512  * \param write_timestamp            write current timestamps*
00513  * \param write_operational_set      write current operational datasets *
00514  * \param write_challenge            add challenge to the message
00515  * \param msg_ptr                    additional buffer addded to message
00516  * \param msg_len                    length of the additional message
00517  * \return 0,                        Command OK
00518  * \return <0                        Command Fail
00519  */
00520 int thread_test_mle_message_send(int8_t interface_id, uint8_t *dst_address, uint8_t msg_id, bool write_src_addr, bool write_leader_data, bool write_network_data, bool write_timestamp, bool write_operational_set, bool write_challenge, uint8_t *msg_ptr, uint8_t msg_len);
00521 
00522 
00523 /**
00524  * \brief Set extension name.
00525  *
00526  * \param interface_id               Network Interface
00527  * \param extension_name             Extension name string
00528  *
00529  * \return 0                         OK
00530  * \return <0                        Failure
00531  */
00532 int thread_test_extension_name_set(int8_t interface_id, char extension_name[16]);
00533 #ifdef __cplusplus
00534 }
00535 #endif
00536 
00537 #endif /* DOXYGEN */
00538 #endif /* NET_THREAD_TEST_H_ */