From 288648df6fa33c974824bd023a6baba11d6eefd8 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 11 Nov 2024 19:27:08 -0700 Subject: libdhcp: Move files around --- libdhcp/include/libdhcp/client.h | 158 +++++++++++++++++++++++++++++++++++++++ libdhcp/include/libdhcp/dhcp.h | 158 --------------------------------------- 2 files changed, 158 insertions(+), 158 deletions(-) create mode 100644 libdhcp/include/libdhcp/client.h delete mode 100644 libdhcp/include/libdhcp/dhcp.h (limited to 'libdhcp/include') diff --git a/libdhcp/include/libdhcp/client.h b/libdhcp/include/libdhcp/client.h new file mode 100644 index 0000000..6037a3b --- /dev/null +++ b/libdhcp/include/libdhcp/client.h @@ -0,0 +1,158 @@ +/* libdhcp/client.h - A DHCP client + * + * Copyright (C) 2024 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Internet/DHCP/dhcp.h + * + * Copyright (c) 2013, WIZnet Co., LTD. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * ----------------------------------------------------------------------------- + * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/license.txt + * + * Copyright (c) 2014 WIZnet Co.,Ltd. + * Copyright (c) WIZnet ioLibrary Project. + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#ifndef _LIBDHCP_DHCP_H_ +#define _LIBDHCP_DHCP_H_ + +#include +#include "hw/w5500.h" + +enum dhcp_event { + DHCP_ASSIGN, + DHCP_UPDATE, + DHCP_CONFLICT, +}; + +typedef void (*dhcp_callback_t)(enum dhcp_event, struct dhcp_lease); + +/* Retry to processing DHCP */ +#define MAX_DHCP_RETRY 2 ///< Maximum retry count +#define DHCP_WAIT_TIME 10 ///< Wait Time 10s + +/* + * @brief return value of @ref DHCP_run() + */ +enum { + DHCP_RET_FAILED = 0, // Processing Fail + DHCP_RET_RUNNING, // Processing DHCP protocol + DHCP_RET_IP_ASSIGN, // First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign) + DHCP_RET_IP_CHANGED, // Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update) + DHCP_RET_IP_LEASED, // Stand by + DHCP_RET_STOPPED // Stop processing DHCP protocol +}; + +/* + * @brief DHCP client initialization (outside of the main loop) + * @param buf - buffer for processing DHCP message + */ +void DHCP_init(void *buf); + +/* + * @brief DHCP 1s Tick Timer handler + * @note SHOULD BE register to your system 1s Tick timer handler + */ +void DHCP_time_handler(void); + +/* + * @brief DHCP client in the main loop + * @return The value is as the follow \n + * @ref DHCP_FAILED \n + * @ref DHCP_RUNNING \n + * @ref DHCP_IP_ASSIGN \n + * @ref DHCP_IP_CHANGED \n + * @ref DHCP_IP_LEASED \n + * @ref DHCP_STOPPED \n + * + * @note This function is always called by you main task. + */ +uint8_t DHCP_run(struct w5500 *chip, uint8_t socknum, dhcp_callback_t cb); +//uint8_t DHCP_run(implements_net_packet_conn *sock, dhcp_callback_t cb); + +/* + * @brief Stop DHCP processing + * @note If you want to restart. call DHCP_init() and DHCP_run() + */ +void DHCP_stop(implements_net_packet_conn *sock); + +void xhandle(uint8_t opt_typ, uint8_t opt_len, uint8_t *opt_dat) { + switch (opt_typ) { + case DHCP_OPT_SUBNET_MASK: + if (opt_len != 4) + return; + global_lease.subnet_mask.octets[0] = opt_dat[0]; + global_lease.subnet_mask.octets[1] = opt_dat[1]; + global_lease.subnet_mask.octets[2] = opt_dat[2]; + global_lease.subnet_mask.octets[3] = opt_dat[3]; + case DHCP_OPT_ROUTER : + if (opt_len < 4) + return; + global_lease.gateway.octets[0] = opt_dat[0]; + global_lease.gateway.octets[1] = opt_dat[1]; + global_lease.gateway.octets[2] = opt_dat[2]; + global_lease.gateway.octets[3] = opt_dat[3]; + break; + case DHCP_OPT_DOMAIN_SERVER : + if (opt_len < 4) + return; + global_lease.dns.octets[0] = opt_dat[0]; + global_lease.dns.octets[1] = opt_dat[1]; + global_lease.dns.octets[2] = opt_dat[2]; + global_lease.dns.octets[3] = opt_dat[3]; + break; + } +} + +#endif /* _LIBDHCP_DHCP_H_ */ diff --git a/libdhcp/include/libdhcp/dhcp.h b/libdhcp/include/libdhcp/dhcp.h deleted file mode 100644 index 0b4c06f..0000000 --- a/libdhcp/include/libdhcp/dhcp.h +++ /dev/null @@ -1,158 +0,0 @@ -/* libdhcp/dhcp.h - A DHCP client - * - * Copyright (C) 2024 Luke T. Shumaker - * SPDX-License-Identifier: AGPL-3.0-or-later - * - * ----------------------------------------------------------------------------- - * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/Internet/DHCP/dhcp.h - * - * Copyright (c) 2013, WIZnet Co., LTD. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * SPDX-License-Identifier: BSD-3-Clause - * - * ----------------------------------------------------------------------------- - * https://github.com/Wiznet/ioLibrary_Driver/blob/b981401e7f3d07015619adf44c13998e13e777f9/license.txt - * - * Copyright (c) 2014 WIZnet Co.,Ltd. - * Copyright (c) WIZnet ioLibrary Project. - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * SPDX-License-Identifier: MIT - */ - -#ifndef _LIBDHCP_DHCP_H_ -#define _LIBDHCP_DHCP_H_ - -#include -#include "hw/w5500.h" - -enum dhcp_event { - DHCP_ASSIGN, - DHCP_UPDATE, - DHCP_CONFLICT, -}; - -typedef void (*dhcp_callback_t)(enum dhcp_event, struct dhcp_lease); - -/* Retry to processing DHCP */ -#define MAX_DHCP_RETRY 2 ///< Maximum retry count -#define DHCP_WAIT_TIME 10 ///< Wait Time 10s - -/* - * @brief return value of @ref DHCP_run() - */ -enum { - DHCP_RET_FAILED = 0, // Processing Fail - DHCP_RET_RUNNING, // Processing DHCP protocol - DHCP_RET_IP_ASSIGN, // First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign) - DHCP_RET_IP_CHANGED, // Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update) - DHCP_RET_IP_LEASED, // Stand by - DHCP_RET_STOPPED // Stop processing DHCP protocol -}; - -/* - * @brief DHCP client initialization (outside of the main loop) - * @param buf - buffer for processing DHCP message - */ -void DHCP_init(void *buf); - -/* - * @brief DHCP 1s Tick Timer handler - * @note SHOULD BE register to your system 1s Tick timer handler - */ -void DHCP_time_handler(void); - -/* - * @brief DHCP client in the main loop - * @return The value is as the follow \n - * @ref DHCP_FAILED \n - * @ref DHCP_RUNNING \n - * @ref DHCP_IP_ASSIGN \n - * @ref DHCP_IP_CHANGED \n - * @ref DHCP_IP_LEASED \n - * @ref DHCP_STOPPED \n - * - * @note This function is always called by you main task. - */ -uint8_t DHCP_run(struct w5500 *chip, uint8_t socknum, dhcp_callback_t cb); -//uint8_t DHCP_run(implements_net_packet_conn *sock, dhcp_callback_t cb); - -/* - * @brief Stop DHCP processing - * @note If you want to restart. call DHCP_init() and DHCP_run() - */ -void DHCP_stop(implements_net_packet_conn *sock); - -void xhandle(uint8_t opt_typ, uint8_t opt_len, uint8_t *opt_dat) { - switch (opt_typ) { - case DHCP_OPT_SUBNET_MASK: - if (opt_len != 4) - return; - global_lease.subnet_mask.octets[0] = opt_dat[0]; - global_lease.subnet_mask.octets[1] = opt_dat[1]; - global_lease.subnet_mask.octets[2] = opt_dat[2]; - global_lease.subnet_mask.octets[3] = opt_dat[3]; - case DHCP_OPT_ROUTER : - if (opt_len < 4) - return; - global_lease.gateway.octets[0] = opt_dat[0]; - global_lease.gateway.octets[1] = opt_dat[1]; - global_lease.gateway.octets[2] = opt_dat[2]; - global_lease.gateway.octets[3] = opt_dat[3]; - break; - case DHCP_OPT_DOMAIN_SERVER : - if (opt_len < 4) - return; - global_lease.dns.octets[0] = opt_dat[0]; - global_lease.dns.octets[1] = opt_dat[1]; - global_lease.dns.octets[2] = opt_dat[2]; - global_lease.dns.octets[3] = opt_dat[3]; - break; - } -} - -#endif /* _LIBDHCP_DHCP_H_ */ -- cgit v1.2.3-2-g168b