Skip to content

Commit

Permalink
Merge pull request Samsung#3325 from sunghan-chang/sync
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
SeonghoByeon authored Jun 5, 2019
2 parents 1d7cc7f + e590d43 commit 1eb6c4a
Show file tree
Hide file tree
Showing 149 changed files with 18,817 additions and 18,414 deletions.
4 changes: 2 additions & 2 deletions apps/examples/testcase/le_tc/filesystem/fs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3559,7 +3559,7 @@ static void tc_libc_stdio_ungetc(void)
* @precondition NA
* @postcondition NA
*/
#ifdef CONFIG_BCH
#if defined(CONFIG_BCH) && !defined(CONFIG_BUILD_PROTECTED)
static void tc_fs_driver_ramdisk_ops(void)
{
uint8_t *buffer;
Expand Down Expand Up @@ -3705,7 +3705,7 @@ int tc_filesystem_main(int argc, char *argv[])
tc_libc_stdio_setvbuf();
#endif
tc_fs_mqueue_ops();
#ifdef CONFIG_BCH
#if defined(CONFIG_BCH) && !defined(CONFIG_BUILD_PROTECTED)
tc_fs_driver_ramdisk_ops();
#endif
tc_libc_stdio_meminstream();
Expand Down
85 changes: 33 additions & 52 deletions external/dhcpc/dhcpc_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@
#include <errno.h>
#include <debug.h>
#include <net/if.h>

#include <sys/ioctl.h>
#include <netdb.h>
#include <protocols/dhcpc.h>
#include <netutils/netlib.h>

#include <net/lwip/netif.h>
#include <net/lwip/netifapi.h>

/****************************************************************************
* Definitions
Expand Down Expand Up @@ -111,68 +110,50 @@
****************************************************************************/
int dhcp_client_start(const char *intf)
{
ndbg("[DHCPC] LWIP DHCPC started\n");
struct netif *cur_netif;
cur_netif = netif_find(intf);
if (cur_netif == NULL) {
ndbg("[DHCPC] No network interface for dhcpc\n");
return -1;
int ret = -1;
struct req_lwip_data req;

int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
printf("socket() failed with errno: %d\n", errno);
return ret;
}
int32_t timeleft = CONFIG_LWIP_DHCPC_TIMEOUT;
struct in_addr local_ipaddr;
struct in_addr local_netmask;
struct in_addr local_gateway;

struct in_addr ip_check;
memset(&req, 0, sizeof(req));
req.type = DHCPCSTART;
req.host_name = intf;

/* Initialize dhcp structure if exists */
if (netif_dhcp_data(cur_netif)) {
netifapi_dhcp_stop(cur_netif);
ret = ioctl(sockfd, SIOCLWIP, (unsigned long)&req);
if (ret == ERROR) {
printf("ioctl() failed with errno: %d\n", errno);
close(sockfd);
return ret;
}

local_ipaddr.s_addr = IPADDR_ANY;
local_netmask.s_addr = IPADDR_BROADCAST;
local_gateway.s_addr = IPADDR_ANY;
DHCPC_SET_IP4ADDR(intf, local_ipaddr, local_netmask, local_gateway);
err_t res = netifapi_dhcp_start(cur_netif);
if (res) {
ndbg("[DHCPC] dhcpc_start failure %d\n", res);
return -1;
}
ndbg("[DHCPC] dhcpc_start success, waiting IP address (timeout %d secs)\n", timeleft);
while (netifapi_dhcp_address_valid(cur_netif) != 0) {
usleep(100000);
timeleft -= 100;
if (timeleft <= 0) {
ndbg("[DHCPC] dhcpc_start timeout\n");
netifapi_dhcp_stop(cur_netif);
return -1;
}
}
int ret = netlib_get_ipv4addr(intf, &ip_check);
if (ret == -1) {
ndbg("[DHCPC] fail to get IP address\n");
netifapi_dhcp_stop(cur_netif);
return -1;
}
ndbg("[DHCPC] dhcpc_start - got IP address %s\n", inet_ntoa(ip_check));
return OK;
ret = req.req_res;
close(sockfd);
return ret;
}

/****************************************************************************
* Name: dhcp_client_stop
****************************************************************************/
void dhcp_client_stop(const char *intf)
{
struct in_addr in = { .s_addr = INADDR_NONE };
DHCPC_SET_IP4ADDR(intf, in, in, in);
struct netif *cur_netif;
cur_netif = netif_find(intf);
if (cur_netif == NULL) {
ndbg("[DHCPC] No network interface for dhcpc\n");
struct req_lwip_data req;

int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
printf("socket() failed with errno: %d\n", errno);
return;
}
netifapi_dhcp_stop(cur_netif);
ndbg("[DHCPC] dhcpc_stop -release IP address (lwip)\n");

memset(&req, 0, sizeof(req));
req.type = DHCPCSTOP;
req.host_name = intf;

(void)ioctl(sockfd, SIOCLWIP, (unsigned long)&req);

close(sockfd);
return;
}
193 changes: 139 additions & 54 deletions external/dhcpd/dhcpd_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
* Included Files
****************************************************************************/

#include <stdio.h>

#include <tinyara/config.h> /* TinyAra configuration */
#include <stdio.h>
#include <debug.h> /* For ndbg, vdbg */
#include <tinyara/compiler.h> /* For CONFIG_CPP_HAVE_WARNING */
#include <protocols/dhcpd.h> /* Advertised DHCPD APIs */
Expand All @@ -74,14 +74,9 @@
#include <semaphore.h>
#include <pthread.h>
#include <netutils/netlib.h>

#include <net/lwip/netif.h>
#include <net/lwip/netifapi.h>

#undef nvdbg
#undef ndbg
#define ndbg(...) printf(__VA_ARGS__)
#define nvdbg(...) printf(__VA_ARGS__)
#include <mqueue.h>
#include <sys/ioctl.h>
#include <netdb.h>

/****************************************************************************
* Global Data
Expand All @@ -92,15 +87,85 @@
#define DHCP_SERVER_PORT 67
#define DHCP_CLIENT_PORT 68

/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static pthread_t g_dhcpd_tid = -1;
static int g_dhcpd_term = 0;

struct dhcp_join_data {
char *intf;
dhcp_sta_joined fn;
};
typedef struct dhcp_join_data dhcp_join_data_s;

/****************************************************************************
* Private Functions
****************************************************************************/
#define DHCPD_MQ_NAME "dhcpd_queue"
#define DHCPD_MQ_LEN 11
#define DHCPD_MQ_MAX_LEN 20

void *_dhcpd_join_handler(void *arg)
{
dhcp_join_data_s *data = (dhcp_join_data_s *)arg;
int sockfd = 0;
struct req_lwip_data req;
int ret = ERROR;
struct mq_attr attr;
attr.mq_maxmsg = DHCPD_MQ_MAX_LEN;
attr.mq_msgsize = DHCPD_MQ_LEN;
attr.mq_flags = 0;
attr.mq_curmsgs = 0;

mqd_t md = mq_open(DHCPD_MQ_NAME, O_RDWR | O_NONBLOCK |O_CREAT, 0666, &attr);
if (md == (mqd_t)ERROR) {
ndbg("Failed to open mq\n");
goto go_out;
}

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
ndbg("socket() failed with errno: %d\n", errno);
goto go_out;
}

memset(&req, 0, sizeof(req));
req.type = DHCPDSTART;
req.host_name = data->intf;

ret = ioctl(sockfd, SIOCLWIP, (unsigned long)&req);
if (ret == ERROR) {
ndbg("ioctl() failed with errno: %d\n", errno);
goto go_out;
}

while (!g_dhcpd_term) {
char msg[DHCPD_MQ_LEN];
memset(msg, 0, DHCPD_MQ_LEN);
int prio = 0;
int nbytes = mq_receive(md, msg, DHCPD_MQ_LEN, &prio);
if (nbytes <= 0) {
if (errno != EAGAIN) {
ndbg("mq receive none (errno %d)\n", errno);
break;
}
} else {
data->fn();
}
sleep(1);
}

go_out:
free(data->intf);
free(data);
if (md > 0) {
mq_close(md);
}
if (sockfd > 0) {
close(sockfd);
}
return NULL;

}

/****************************************************************************
* Global Functions
****************************************************************************/
Expand All @@ -109,66 +174,86 @@
****************************************************************************/
int dhcp_server_status(char *intf)
{
struct netif *cur_netif;
cur_netif = netif_find(intf);
if (cur_netif == NULL) {
ndbg("[DHCPS] no network interface for dhcpd start\n");
return 0;
int ret = ERROR;
struct req_lwip_data req;

int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
ndbg("socket() failed with errno: %d\n", errno);
return ret;
}

if (cur_netif->dhcps_pcb == NULL) {
ndbg("[DHCPS] DHCP server closed\n");
return 0;
} else {
ndbg("[DHCPS] DHCP server opened\n");
return 1;
memset(&req, 0, sizeof(req));
req.type = DHCPDSTATUS;
req.host_name = intf;

ret = ioctl(sockfd, SIOCLWIP, (unsigned long)&req);
if (ret == ERROR) {
ndbg("ioctl() failed with errno: %d\n", errno);
close(sockfd);
return ret;
}

ret = req.req_res;
close(sockfd);
return ret;
}

/****************************************************************************
* Name: dhcps_server_start
****************************************************************************/


int dhcp_server_start(char *intf, dhcp_sta_joined dhcp_join_cb)
{
struct netif *cur_netif;
cur_netif = netif_find(intf);
if (cur_netif == NULL) {
ndbg("[DHCPS] no network interface for dhcpd start\n");
return -1;
}
if (dhcp_join_cb) {
if (dhcps_register_cb(dhcp_join_cb) != ERR_OK) {
ndbg("[DHCPS] link callback fail\n");
return -1;
}
}
dhcp_join_data_s *data = (dhcp_join_data_s *)malloc(sizeof(dhcp_join_data_s));
data->intf = (char *)malloc(strlen(intf)+1);
memcpy(data->intf, intf, strlen(intf) + 1);
data->fn = dhcp_join_cb;

if (netifapi_dhcps_start(cur_netif) == ERR_OK) {
ndbg("[DHCPS] started successfully (LWIP)\n");
return OK;
int ret = ERROR;
g_dhcpd_term = 0;
ret = pthread_create(&g_dhcpd_tid, NULL, _dhcpd_join_handler, (void *)data);
pthread_setname_np(g_dhcpd_tid, "dhcpd cb handler");
if (ret < 0) {
g_dhcpd_term = 1;
ndbg("[dhcpd] create iotapi handler fail(%d) errno %d\n", ret, errno);
return ERROR;
}

return -1;
return ret;
}

/****************************************************************************
* Name: dhcps_server_stop
****************************************************************************/
int dhcp_server_stop(char *intf)
{
struct netif *cur_netif;
cur_netif = netif_find(intf);
if (cur_netif == NULL) {
ndbg("[DHCPS] no network interface for dhcpd start\n");
return -1;
int ret = ERROR;
struct req_lwip_data req;
g_dhcpd_term = 1;
sleep(1);

pthread_join(g_dhcpd_tid, NULL);

int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
ndbg("socket() failed with errno: %d\n", errno);
return ret;
}
if (cur_netif->dhcps_pcb == NULL) {
ndbg("[DHCPS] stop dhcpd fail: no pcb\n");
return -1;

memset(&req, 0, sizeof(req));
req.type = DHCPDSTOP;
req.host_name = intf;

ret = ioctl(sockfd, SIOCLWIP, (unsigned long)&req);
if (ret == ERROR) {
ndbg("ioctl() failed with errno: %d\n", errno);
close(sockfd);
return ret;
}

netifapi_dhcps_stop(cur_netif);
ndbg("[DHCPS] stopped successfully (LWIP)\n");
ret = req.req_res;
close(sockfd);

return OK;
return ret;
}
4 changes: 4 additions & 0 deletions os/KernelLibs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ ifneq ($(CONFIG_BINFMT_DISABLE),y)
TINYARALIBS += $(LIBRARIES_DIR)$(DELIM)libbinfmt$(LIBEXT)
endif

ifeq ($(CONFIG_RTK_WLAN),y)
TINYARALIBS += $(LIBRARIES_DIR)$(DELIM)librtl$(LIBEXT)
endif

# Add library for wifi driver
TINYARALIBS += $(LIBRARIES_DIR)$(DELIM)libwifidriver$(LIBEXT)
# Add library for wifi stack
Expand Down
Loading

0 comments on commit 1eb6c4a

Please sign in to comment.