Rizky Ardi Maulana / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dhcp_service_api.h Source File

dhcp_service_api.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013-2015 ARM Limited. All rights reserved.
00003  *
00004  * SPDX-License-Identifier: LicenseRef-PBL
00005  *
00006  * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * https://www.mbed.com/licenses/PBL-1.0
00010  *
00011  * See the License for the specific language governing permissions and limitations under the License.
00012  *
00013  */
00014 
00015 #ifndef DHCP_SERVICE_API_H_
00016 #define DHCP_SERVICE_API_H_
00017 
00018 #include <ns_types.h>
00019 /**
00020  * \file dhcp_service_api.h
00021  * \brief DHCP server connection interfaces
00022  *
00023  * \section dhcp-service DHCP Service Instance
00024  * - dhcp_service_init(), Initializes a DHCP service.
00025  * - dhcp_service_delete(), Removes the DHCP service.
00026  *
00027  * \section dhcp-msg DHCP Service Messages
00028  * - dhcp_service_send_req(), Sends out DHCP request messages.
00029  * - dhcp_service_send_resp(), Sends out DHCP response messages.
00030  *
00031  * \section dhcp-tim DHCP Service Timers (retry timers)
00032  * - dhcp_service_send_req(), Sends out DHCP request messages.
00033  * - dhcp_service_set_retry_timers(), Sets the retransmission parameters.
00034  * - dhcp_service_req_remove(), Stops retrying and retransmissions.
00035  * - dhcp_service_timer_tick(), Indicates if a timeout occurred.
00036  *
00037  */
00038 
00039 /** Defines Debug Trace String for DHCP service */
00040 #define DHCP_SERVICE_API_TRACE_STR "DHcS"
00041 
00042 /*
00043  * Return values for callbacks
00044  */
00045 
00046 /** Message belongs to someone else. */
00047 #define RET_MSG_NOT_MINE 0
00048 /** Message is handled. */
00049 #define RET_MSG_ACCEPTED 1
00050 /** Message is not the final one and needs to hold on a bit. */
00051 #define RET_MSG_WAIT_ANOTHER -1
00052 /** Message is unexpected or corrupted. */
00053 #define RET_MSG_CORRUPTED -2
00054 
00055 /** \name DHCP options */
00056 ///@{
00057 #define TX_OPT_NONE                     0x00    /**< No options. */
00058 #define TX_OPT_USE_SHORT_ADDR           0x01    /**< Use short addresses. */
00059 #define TX_OPT_MULTICAST_HOP_LIMIT_64   0x02    /**< Use multicast hop limit of 64. */
00060 ///@}
00061 
00062 typedef enum dhcp_instance_type
00063 {
00064     DHCP_INSTANCE_CLIENT,
00065     DHCP_INSTANCE_SERVER
00066 } dhcp_instance_type_e;
00067 
00068 /**
00069  * \brief DHCP Service receive callback.
00070  *
00071  * When the DHCP service receives a DHCP message it will go through a list of registered DHCP services instances
00072  * until some instance acknowledges that the message belongs to it.
00073  * \param instance_id An instance of registered server.
00074  * \param msg_tr_id The message transaction ID.
00075  * \param msg_ptr An allocated message pointer. Should not deallocate unless RET_MSG_ACCEPTED returned (then responsibility of client).
00076  * \param msg_len The length of the message.
00077  *
00078  * Return values
00079  * \return RET_MSG_ACCEPTED - Message is handled.
00080  * \return RET_MSG_CORRUPTED - Message is corrupted.
00081  * \return RET_MSG_NOT_MINE - Message belongs to someone else.
00082  */
00083 
00084 typedef int (dhcp_service_receive_req_cb)(uint16_t instance_id, uint32_t msg_tr_id, uint8_t msg_name, uint8_t *msg_ptr, uint16_t msg_len);
00085 
00086 /**
00087  * \brief DHCP Service Message Response callback.
00088  *
00089  * When the DHCP service receives a response to a DHCP message, this callback receives it.
00090  *
00091  * \param instance_id An instance of a registered server.
00092  * \param ptr A pointer for the client object.
00093  * \param msg_ptr An allocated message pointer. Should not deallocate unless RET_MSG_ACCEPTED returned (then responsibility of client).
00094  * \param msg_len The length of the message.
00095  *
00096  * Return values
00097  * \return RET_MSG_ACCEPTED - Message is handled
00098  * \return RET_MSG_WAIT_ANOTHER - This message was not the last one for this transaction and a new reply is expected.
00099  */
00100 
00101 typedef int (dhcp_service_receive_resp_cb)(uint16_t instance_id, void *ptr, uint8_t msg_name,  uint8_t *msg_ptr, uint16_t msg_len);
00102 
00103 
00104 /**
00105  * \brief Initialize a new DHCP service instance.
00106  *
00107  * Creates and shares the socket for other DHCP services.
00108  *
00109  * \param interface_id Interface for the new DHCP instance.
00110  * \param instance_type The type of the new DHCP instance.
00111  * \param A callback function to receive DHCP messages.
00112  *
00113  * \return Instance ID that is used to identify the service.
00114  */
00115 
00116 uint16_t dhcp_service_init(int8_t interface_id, dhcp_instance_type_e instance_type, dhcp_service_receive_req_cb *receive_req_cb);
00117 
00118 /**
00119 * \brief Deletes a server instance.
00120 *
00121 * Removes all data related to this instance.
00122 *
00123 * \param instance The instance ID of the registered server.
00124 */
00125 void dhcp_service_delete(uint16_t instance);
00126 
00127 /**
00128 * \brief Sends a DHCP response message.
00129 *
00130 * \param msg_tr_id The message transaction ID.
00131 * \param options Options for this request.
00132 * \param msg_ptr An allocated message pointer. Should not deallocate unless RET_MSG_ACCEPTED returned (then responsibility of client).
00133 * \param msg_len The length of the message.
00134 *
00135 * \return 0, if everything went fine.
00136 * \return -1, if error occurred.
00137 */
00138 int dhcp_service_send_resp(uint32_t msg_tr_id, uint8_t options, uint8_t *msg_ptr, uint16_t msg_len);
00139 
00140 
00141 /**
00142  * \brief Sends DHCP request message.
00143  *
00144  * Service takes care of retransmissions.
00145  *
00146  * \param instance_id The instance ID of the registered server.
00147  * \param options Options for this request.
00148  * \param ptr A void pointer to the client object.
00149  * \param addr The address of the server.
00150  * \param msg_ptr An allocated message pointer. This pointer is the responsibility of the service after this call.
00151  * \param msg_len The length of the message.
00152  * \param receive_resp_cb Callback pointer
00153  *
00154  * \return Transaction ID of the DHCP transaction
00155  * \return 0, if error occurred.
00156  */
00157 uint32_t dhcp_service_send_req(uint16_t instance_id, uint8_t options, void *ptr, const uint8_t addr[static 16], uint8_t *msg_ptr, uint16_t msg_len, dhcp_service_receive_resp_cb *receive_resp_cb);
00158 
00159 /**
00160  * \brief Setting retransmission parameters.
00161  *
00162  * Sets the retransmission parameters for this transaction.
00163  *
00164  * \param msg_tr_id The message transaction ID.
00165  * \param timeout_init An initial timeout value.
00166  * \param timeout_max The maximum timeout value when initial timeout is doubled with every retry.
00167  * \param retrans_max The maximum number of retries after which an error is received.
00168  *
00169  */
00170 void dhcp_service_set_retry_timers(uint32_t msg_tr_id, uint16_t timeout_init, uint16_t timeout_max, uint8_t retrans_max);
00171 
00172 /**
00173  * \brief Stops transactions for a message (retransmissions).
00174  *
00175  * Clears off sending retransmissions for a particular message transaction by finding it via its message transaction ID.
00176  *
00177  * \param msg_tr_id The message transaction ID.
00178  *
00179  */
00180 void dhcp_service_req_remove(uint32_t msg_tr_id);
00181 
00182 /**
00183  * \brief Timer tick function for retransmissions.
00184  *
00185  * Retransmission timer ticks should be increased with 100ms interval, if necessary. One tick is one millisecond.
00186  *
00187  */
00188 bool dhcp_service_timer_tick(uint16_t ticks);
00189 
00190 
00191 #endif //DHCP_SERVICE_API_H_