Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: nRF51_Vdd TextLCD BME280
libDHCPv6.h
00001 /* 00002 * Copyright (c) 2014-2015, 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 /* 00019 * \file libDHCPv6.h 00020 * \brief Add short description about this file!!! 00021 * 00022 */ 00023 00024 #ifndef LIBDHCPV6_H_ 00025 #define LIBDHCPV6_H_ 00026 00027 #include "ns_list.h" 00028 00029 typedef struct { 00030 uint16_t linkType; 00031 uint8_t *linkID; 00032 } dhcp_link_options_params_t; 00033 typedef struct { 00034 uint16_t type; 00035 uint16_t len; 00036 uint8_t *msg_ptr; 00037 } dhcp_options_msg_t; 00038 00039 typedef struct { 00040 uint8_t *ipv6Address; 00041 uint32_t validLifeTime; 00042 uint32_t preferredLifeTime; 00043 } dhcp_ia_addressoptions_msg_t; 00044 00045 typedef struct { 00046 uint8_t *requestedAddress; 00047 uint32_t validLifeTime; 00048 uint32_t preferredLifeTime; 00049 } dhcpv6_ia_non_temporal_address_s; 00050 00051 typedef struct { 00052 dhcp_link_options_params_t clientDUID; 00053 dhcp_link_options_params_t serverDUID; 00054 uint32_t transaction_ID; 00055 uint32_t iaId; 00056 uint32_t T0; 00057 uint32_t T1; 00058 bool rapidCommit; 00059 } dhcpv6_reply_packet_s; 00060 00061 typedef struct { 00062 uint8_t *vendorData; 00063 uint16_t vendorDataLength; 00064 } dhcpv6_vendor_data_packet_s; 00065 00066 typedef struct { 00067 uint8_t messageType; 00068 uint32_t transActionId; 00069 dhcp_link_options_params_t clientDUID; 00070 uint32_t iaID; 00071 uint32_t timerT0; 00072 uint32_t timerT1; 00073 uint16_t *requestedOptionList; 00074 uint8_t requestedOptionCnt; 00075 } dhcpv6_solication_base_packet_s; 00076 00077 typedef struct { 00078 uint32_t iaId; 00079 uint32_t T0; 00080 uint32_t T1; 00081 uint8_t *nonTemporalAddress; 00082 uint32_t validLifeTime; 00083 uint32_t preferredValidLifeTime; 00084 } dhcp_ia_non_temporal_params_t; 00085 00086 typedef struct dhcpv6_ia_nontemp_addres_entry_t { 00087 uint32_t validLifetime; 00088 uint32_t preferredTime; 00089 uint8_t addressPrefix[16]; 00090 } dhcpv6_ia_nontemp_addres_entry_t; 00091 00092 00093 typedef struct dhcpv6_client_server_entry_s { 00094 int8_t interfaceId; 00095 uint8_t instanceId; // instance identifying specific client 00096 bool useServerAddress; //This indicate 00097 bool iaNonTemporalStructValid; 00098 bool GlobalAddress; 00099 uint8_t server_address[16]; 00100 uint8_t serverLinkId[8]; 00101 uint16_t serverLinkType; 00102 uint8_t clientId[8]; 00103 uint16_t clientLinkIdType; 00104 uint32_t T0; 00105 uint32_t T1; 00106 uint32_t IAID; //Take random for that 00107 uint32_t transActionId; //Client save this and use for get 00108 uint32_t reNewTimer; 00109 dhcpv6_ia_nontemp_addres_entry_t iaNontemporalAddress; // Dynamical Part 00110 ns_list_link_t link; /*!< List link entry */ 00111 } dhcpv6_client_server_data_t; 00112 00113 typedef NS_LIST_HEAD (dhcpv6_client_server_data_t, link) dhcpv6_client_server_entry_s; 00114 00115 /** UDP Port Number definition */ 00116 #define DHCPV6_SERVER_PORT 547 00117 #define DHCPV6_CLIENT_PORT 546 00118 00119 /** Message type Definition */ 00120 #define DHCPV6_SOLICATION_TYPE 1 00121 #define DHCPV6_ADVERTISMENT_TYPE 2 00122 #define DHCPV6_REQUEST_TYPE 3 00123 #define DHCPV6_RENEW_TYPE 5 00124 #define DHCPV6_REPLY_TYPE 7 00125 #define DHCPV6_RELEASE_TYPE 8 00126 #define DHCPV6_LEASEQUERY_TYPE 14 00127 #define DHCPV6_LEASEQUERY_REPLY_TYPE 15 00128 00129 /* DHCP timeout values for different messages RFC3315 00130 * LQ from RFC5007 00131 * UPDATE from RFC7083 00132 * 00133 * Timers are 16-bit, and in 1/10s ticks, so times must be <=6553 00134 */ 00135 00136 #define SOL_MAX_DELAY 1 //sec Max delay of first Solicit 00137 #define SOL_TIMEOUT 1 //sec Initial Solicit timeout 00138 #define SOL_MAX_RT 3600 //secs Max Solicit timeout value 00139 #define REQ_TIMEOUT 1 //sec Initial Request timeout 00140 #define REQ_MAX_RT 30 //secs Max Request timeout value 00141 #define REQ_MAX_RC 10 // Max Request retry attempts 00142 #define CNF_MAX_DELAY 1 //sec Max delay of first Confirm 00143 #define CNF_TIMEOUT 1 //sec Initial Confirm timeout 00144 #define CNF_MAX_RT 4 //secs Max Confirm timeout 00145 #define CNF_MAX_RD 10 //secs Max Confirm duration 00146 #define REN_TIMEOUT 10 //secs Initial Renew timeout 00147 #define REN_MAX_RT 600 //secs Max Renew timeout value 00148 #define REB_TIMEOUT 10 //secs Initial Rebind timeout 00149 #define REB_MAX_RT 600 //secs Max Rebind timeout value 00150 #define INF_MAX_DELAY 1 //sec Max delay of first Information-request 00151 #define INF_TIMEOUT 1 //sec Initial Information-request timeout 00152 #define INF_MAX_RT 120 //secs Max Information-request timeout value 00153 #define REL_TIMEOUT 1 //sec Initial Release timeout 00154 #define REL_MAX_RC 5 // MAX Release attempts 00155 #define DEC_TIMEOUT 1 //sec Initial Decline timeout 00156 #define DEC_MAX_RC 5 // Max Decline attempts 00157 #define REC_TIMEOUT 2 //secs Initial Reconfigure timeout 00158 #define REC_MAX_RC 8 // Max Reconfigure attempts 00159 #define HOP_COUNT_LIMIT 32 // Max hop count in a Relay-forward message 00160 #define LQ_TIMEOUT 1 //sec Initial LEASEQUERY timeout 00161 #define LQ_MAX_RT 10 //secs Max LEASEQUERY timeout value 00162 #define LQ_MAX_RC 5 // Max LEASEQUERY retry attempts 00163 00164 00165 00166 #define DHCP_MESSGAGE_MAX_SUPPORTED_OPTIONS 8 00167 00168 #define DHCPV6_ELAPSED_TIME_OPTION 0x0008 00169 #define DHCPV6_ELAPSED_TIME_OPTION_LEN 0x0002 00170 /** Client Identifier part */ 00171 #define DHCPV6_CLIENT_ID_OPTION 0x001 00172 #define DHCPV6_CLIENT_ID_OPTION_LEN 0x000c 00173 /** Client Identifier part End */ 00174 /** Server Identifier Part */ 00175 #define DHCPV6_SERVER_ID_OPTION 0x002 00176 #define DHCPV6_SERVER_ID_OPTION_LEN 0x000c 00177 #define DHCPV6_SERVER_ID_MAC48_OPTION_LEN 0x000a 00178 #define DHCPV6_SERVER_ID_MAC64_OPTION_LEN 0x000c 00179 /** Server Identifier END */ 00180 /** Common for server and Client Identifier option */ 00181 #define DHCPV6_DUID_LINK_LAYER_TYPE 0x0003 00182 #define DHCPV6_DUID_HARDWARE_EUI64_TYPE 0x001b 00183 #define DHCPV6_DUID_HARDWARE_EUI48_TYPE 0x0001 00184 00185 /** Identity Association part */ 00186 #define DHCPV6_IDENTITY_ASSOCIATION_OPTION 0x0003 00187 #define DHCPV6_IDENTITY_ASSOCIATION_OPTION_MIN_LEN 0x000c 00188 00189 #define DHCPV6_IA_ADDRESS_OPTION 0x0005 00190 #define DHCPV6_IA_ADDRESS_OPTION_LEN 0x0018 00191 00192 #define DHCPV6_OPTION_REQUEST_OPTION 0x0006 00193 00194 #define DHCPV6_OPTION_IA_PREFIX_DELEGATION 0x001a 00195 #define DHCPV6_OPTION_IA_PREFIX_DELEGATION_MIN_LENGTH 0x000c 00196 /** Identity Association END */ 00197 00198 #define DHCPV6_OPTION_VENDOR_SPECIFIC_INFO 0x0011 00199 /** SEQUENCYID, RouterIDMask 32-bit*/ 00200 00201 #define DHCPV6_STATUS_CODE_OPTION 0x000d 00202 #define DHCPV6_STATUS_CODE_OPTION_LEN 0x0002 00203 #define DHCPV6_STATUS_NO_ADDR_AVAILABLE_CODE 0x0002 00204 00205 #define DHCPV6_OPTION_RAPID_COMMIT 0x000E //Define Reply for Solication 00206 #define DHCPV6_OPTION_RAPID_COMMIT_LEN 0x0000 00207 00208 #define DHCPV6_OPTION_CLIENT_DATA 0x002d 00209 00210 #define DHCPV6_OPTION_CLT_TIME 0x002e 00211 00212 /** DHCPv6 client Nontemporal address and server data allocate, free and search */ 00213 dhcpv6_client_server_data_t *libdhcvp6_nontemporalAddress_server_data_allocate(int8_t interfaceId, uint8_t instanceId, uint8_t *duiId, uint16_t duiLinkType, uint8_t *nonTemporalPrefix, uint8_t *serverIPv6Address); 00214 void libdhcvp6_nontemporalAddress_server_data_free(dhcpv6_client_server_data_t *removedEntry); 00215 00216 uint32_t libdhcpv6_renew_time_define(dhcpv6_client_server_data_t *addresInfo); 00217 uint32_t libdhcpv6_txid_get(void); 00218 dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_iaid(uint32_t iaId); 00219 dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_transactionId(uint32_t txId); 00220 dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_prefix(int8_t interfaceId, uint8_t *prefix); 00221 dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_instance(uint8_t instanceId); 00222 uint8_t libdhcpv6_nonTemporal_entry_get_unique_instance_id(void); 00223 00224 00225 /** 00226 * This Function for verify dhcpv6 message payload 00227 * 00228 * \param ptr payload pointer 00229 * \param data_len payload length 00230 * 00231 * return 0 Valid Payload structure 00232 * return <0 Maloformed payload 00233 */ 00234 int libdhcpv6_message_malformed_check(uint8_t *ptr, uint16_t data_len); 00235 00236 int libdhcpv6_message_option_discover(uint8_t *ptr, uint16_t data_len, uint16_t discovered_type, dhcp_options_msg_t *option_info); 00237 00238 /** Static Option sizes */ 00239 #define libdhcpv6_header_size() 4 00240 #define libdhcpv6_ia_address_option_size() 28 00241 #define libdhcpv6_elapsed_time_option_size() 6 00242 #define libdhcpv6_rapid_commit_option_size() 4 00243 #define libdhcvp6_thread_vendor_spesific_option_size() 21 00244 #define libdhcpv6_status_option_size() 6 00245 #define libdhcpv6_client_last_transaction_time_option_size() 8 00246 00247 /** Dynamic Option lengths */ 00248 uint16_t libdhcpv6_duid_option_size(uint16_t linkType); 00249 uint16_t libdhcvp6_request_option_size(uint8_t optionCnt); 00250 uint16_t libdhcpv6_non_temporal_address_size(bool addressDefined); 00251 00252 uint16_t libdhcpv6_solication_message_length(uint16_t clientLinkType, bool addressDefined, uint8_t requestOptionCount); 00253 uint16_t libdhcpv6_address_request_message_len(uint16_t clientLinkType, uint16_t serverLinkType, uint8_t requstOptionCnt); 00254 #ifdef HAVE_DHCPV6_SERVER 00255 uint16_t libdhcpv6_address_reply_message_len(uint16_t clientLinkType, uint16_t serverLinkType, uint16_t vendorDataLen, bool rapidCommon, bool status); 00256 #else 00257 #define libdhcpv6_address_reply_message_len(clientLinkType, serverLinkType, vendorDataLen, rapidCommon, status) 0 00258 #endif 00259 00260 uint8_t *libdhcpv6_generic_nontemporal_address_message_write(uint8_t *ptr, dhcpv6_solication_base_packet_s *packet, dhcpv6_ia_non_temporal_address_s *nonTemporalAddress, dhcp_link_options_params_t *serverLink); 00261 uint8_t *libdhcpv6_reply_message_write(uint8_t *ptr, dhcpv6_reply_packet_s *replyPacket, dhcpv6_ia_non_temporal_address_s *nonTemporalAddress, dhcpv6_vendor_data_packet_s *vendorData); 00262 00263 00264 int libdhcpv6_get_IA_address(uint8_t *ptr, uint16_t data_length, dhcp_ia_non_temporal_params_t *params); 00265 int libdhcpv6_get_duid_by_selected_type_id_opt(uint8_t *ptr, uint16_t data_length, uint16_t type , dhcp_link_options_params_t *params); 00266 int libdhcpv6_compare_DUID(dhcp_link_options_params_t *targetId, dhcp_link_options_params_t *parsedId); 00267 00268 /** 00269 * This Function write dhcpv6 basic header 00270 * 00271 * \param ptr pointer where header will be writed 00272 * \param msgType dhcpv6 message type 00273 * \param transActionId 24-bit unique Transaction ID 00274 * 00275 * return incremented pointer after write 00276 */ 00277 uint8_t *libdhcpv6_header_write(uint8_t *ptr, uint8_t msgType, uint32_t transActionId); 00278 00279 /** 00280 * This Function write dhcpv6 elapsed time option 00281 * 00282 * \param ptr pointer where option will be writed 00283 * \param elapsedTime option elapsed time 00284 * 00285 * return incremented pointer after write 00286 */ 00287 uint8_t *libdhcpv6_elapsed_time_option_write(uint8_t *ptr, uint16_t elapsedTime); 00288 00289 /** 00290 * This Function write dhcpv6 rapid common option 00291 * 00292 * \param ptr pointer where option will be writed 00293 * 00294 * return incremented pointer after write 00295 */ 00296 uint8_t *libdhcpv6_rapid_commit_option_write(uint8_t *ptr); 00297 00298 /** 00299 * This Function write dhcpv6 thread requested vendor spesific data 00300 * 00301 * \param ptr pointer where option will be writed 00302 * \param data Vendor Data 00303 * \param dataLength Vendor Data length 00304 * 00305 * return incremented pointer after write 00306 */ 00307 uint8_t *libdhcvp6_vendor_specific_option_write(uint8_t *ptr, uint8_t *data, uint16_t dataLength); 00308 00309 /** 00310 * This Function write dhcpv6 request option write 00311 * 00312 * \param ptr pointer where option will be writed 00313 * \param optionCnt Option counter for read behind pointer 00314 * \param optionPtr Option list pointer 00315 * return incremented pointer after write 00316 */ 00317 uint8_t *libdhcvp6_request_option_write(uint8_t *ptr, uint8_t optionCnt, uint16_t *optionPtr); 00318 00319 00320 00321 /** 00322 * This Function for Client / Server DUID write for specific link type 00323 * 00324 * \param ptr payload pointer 00325 * \param duidPtr pointer id 00326 * \param duidRole supported values DHCPV6_SERVER_ID_OPTION & DHCPV6_CLIENT_ID_OPTION 00327 * \param linkType supported values DHCPV6_DUID_HARDWARE_EUI64_TYPE & DHCPV6_DUID_HARDWARE_EUI48_TYPE 00328 * 00329 * return incremented pointer after write 00330 */ 00331 uint8_t *libdhcpv6_duid_option_write(uint8_t *ptr, uint16_t duidRole, const dhcp_link_options_params_t *duid); 00332 uint8_t *libdhcpv6_ia_address_option_write(uint8_t *ptr, const uint8_t *addressPtr, uint32_t preferredValidLifeTime, uint32_t validLifeTime); 00333 uint8_t *libdhcpv6_identity_association_option_write(uint8_t *ptr, uint32_t iaID, uint32_t TimerT1, uint32_t TimerT2, bool withAddress); 00334 uint8_t *libdhcpv6_identity_association_option_write_with_status(uint8_t *ptr, uint32_t iaID, uint32_t TimerT1, uint32_t TimerT2, uint16_t status); 00335 uint8_t *libdhcpv6_status_code_write(uint8_t *ptr, uint16_t statusCode); 00336 uint8_t *libdhcpv6_prefix_delegation_info_option_write(uint8_t *ptr, uint32_t iaId); 00337 00338 int libdhcpv6_reply_message_option_validate(dhcp_link_options_params_t *clientId, dhcp_link_options_params_t *serverId, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params, uint8_t *ptr, uint16_t data_length); 00339 00340 #ifdef HAVE_DHCPV6_SERVER 00341 int libdhcpv6_renew_message_options_validate(uint8_t *ptr, uint16_t data_length, dhcp_link_options_params_t *clientLinkData, dhcp_link_options_params_t *serverLinkData, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params); 00342 int libdhcpv6_solication_message_options_validate(uint8_t *ptr, uint16_t data_length, dhcp_link_options_params_t *clientLink, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params); 00343 #else 00344 #define libdhcpv6_renew_message_options_validate(ptr, data_length, clientLinkData, serverLinkData, dhcp_ia_non_temporal_params) -1 00345 #define libdhcpv6_solication_message_options_validate(ptr, data_length, clientLink, dhcp_ia_non_temporal_params) -1 00346 #endif 00347 int libdhcpv6_advertisment_message_option_validate(dhcp_link_options_params_t *clientId, dhcp_link_options_params_t *serverId, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params, uint8_t *ptr, uint16_t data_length); 00348 bool libdhcpv6_rapid_commit_option_at_packet(uint8_t *ptr, uint16_t length); 00349 bool libdhcpv6_time_elapsed_option_at_packet(uint8_t *ptr, uint16_t length); 00350 00351 #endif /* LIBDHCPV6_H_ */
Generated on Tue Jul 12 2022 15:15:47 by
