1 /* 2 * Copyright (C) 2022 Beken Corporation 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <string.h> 16 #include <os/os.h> 17 #include "dhcp-priv.h" 18 19 static beken_thread_t dhcpd_thread; 20 static bool dhcpd_running; 21 dhcp_server_start(void * intrfc_handle)22int dhcp_server_start(void *intrfc_handle) 23 { 24 int ret; 25 26 dhcp_d("DHCP server start request \r\n"); 27 28 dhcp_enable_nack_dns_server(); 29 30 if (dhcpd_running || dhcp_server_init(intrfc_handle)) { 31 return -1; 32 } 33 34 ret = rtos_create_thread(&dhcpd_thread, 35 BEKEN_APPLICATION_PRIORITY, 36 "dhcp-server", 37 (beken_thread_function_t)dhcp_server, 38 DHCP_SERVER_TASK_STACK_SIZE, 39 0); 40 if (ret) { 41 dhcp_free_allocations(); 42 return -1; 43 } 44 45 dhcpd_running = 1; 46 return 0; 47 } 48 dhcp_server_stop(void)49void dhcp_server_stop(void) 50 { 51 dhcp_d("DHCP server stop request\r\n"); 52 if (dhcpd_running) 53 { 54 if (dhcp_send_halt() != 0) 55 { 56 dhcp_w("failed to send halt to DHCP thread\r\n"); 57 return; 58 } 59 60 if (rtos_delete_thread(&dhcpd_thread) != 0) 61 dhcp_w("failed to delete thread\r\n"); 62 dhcpd_running = 0; 63 } 64 else 65 { 66 dhcp_w("server not dhcpd_running.\r\n"); 67 } 68 } 69 // eof 70 71