Skip to content

Commit 56c9317

Browse files
committed
Start dhcp
1 parent ef43f46 commit 56c9317

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

ports/zephyr-cp/common-hal/socketpool/SocketPool.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int socketpool_getaddrinfo_common(const char *host, int service, const struct zs
3737

3838
char service_buf[6];
3939
snprintf(service_buf, sizeof(service_buf), "%d", service);
40+
printk("socketpool_getaddrinfo_common host %s service %s\n", host, service_buf);
4041

4142
return zsock_getaddrinfo(host, service_buf, hints, res);
4243
}
@@ -85,13 +86,14 @@ static mp_obj_t convert_sockaddr(const struct zsock_addrinfo *ai, int port) {
8586
}
8687

8788
static mp_obj_t convert_addrinfo(const struct addrinfo *ai, int port) {
88-
MP_STATIC_ASSERT(AF_INET == SOCKETPOOL_AF_INET);
89-
#if CIRCUITPY_SOCKETPOOL_IPV6
90-
MP_STATIC_ASSERT(AF_INET6 == SOCKETPOOL_AF_INET6);
91-
#endif
92-
// MP_STATIC_ASSERT(AF_UNSPEC == SOCKETPOOL_AF_UNSPEC);
9389
mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
94-
result->items[0] = MP_OBJ_NEW_SMALL_INT(ai->ai_family);
90+
int family = ai->ai_family;
91+
if (ai->ai_family == AF_INET) {
92+
family = SOCKETPOOL_AF_INET;
93+
} else if (ai->ai_family == AF_INET6) {
94+
family = SOCKETPOOL_AF_INET6;
95+
}
96+
result->items[0] = MP_OBJ_NEW_SMALL_INT(family);
9597
result->items[1] = MP_OBJ_NEW_SMALL_INT(ai->ai_socktype);
9698
result->items[2] = MP_OBJ_NEW_SMALL_INT(ai->ai_protocol);
9799
result->items[3] = ai->ai_canonname ? mp_obj_new_str(ai->ai_canonname, strlen(ai->ai_canonname)) : MP_OBJ_NEW_QSTR(MP_QSTR_);
@@ -100,6 +102,12 @@ static mp_obj_t convert_addrinfo(const struct addrinfo *ai, int port) {
100102
}
101103

102104
mp_obj_t common_hal_socketpool_getaddrinfo_raise(socketpool_socketpool_obj_t *self, const char *host, int port, int family, int type, int proto, int flags) {
105+
if (family == SOCKETPOOL_AF_INET) {
106+
family = AF_INET;
107+
} else if (family == SOCKETPOOL_AF_INET6) {
108+
family = AF_INET6;
109+
}
110+
// Proto and type values match BSD.
103111
const struct zsock_addrinfo hints = {
104112
.ai_flags = flags,
105113
.ai_family = family,
@@ -110,7 +118,7 @@ mp_obj_t common_hal_socketpool_getaddrinfo_raise(socketpool_socketpool_obj_t *se
110118
struct addrinfo *res = NULL;
111119
int err = socketpool_getaddrinfo_common(host, port, &hints, &res);
112120
if (err != 0 || res == NULL) {
113-
printk("common_hal_socketpool_getaddrinfo_raise\n");
121+
printk("common_hal_socketpool_getaddrinfo_raise err %d res %p\n", err, res);
114122
common_hal_socketpool_socketpool_raise_gaierror_noname();
115123
}
116124

ports/zephyr-cp/common-hal/wifi/Radio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
392392
printk("common_hal_wifi_radio_connect done: %d\n", result);
393393
if (result == WIFI_STATUS_CONN_SUCCESS) {
394394
printk("success!\n");
395-
k_sleep(K_SECONDS(30));
395+
net_dhcpv4_start(self->sta_netif);
396+
397+
k_poll_signal_reset(&self->done);
398+
self->events[1].state = K_POLL_STATE_NOT_READY;
399+
400+
k_poll(self->events, ARRAY_SIZE(self->events), K_SECONDS((int)10));
396401
return WIFI_RADIO_ERROR_NONE;
397402
} else if (result == WIFI_STATUS_CONN_FAIL) {
398403
return WIFI_RADIO_ERROR_UNSPECIFIED;

ports/zephyr-cp/common-hal/wifi/__init__.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static void _event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_eve
143143
break;
144144
case NET_EVENT_IPV4_ADDR_ADD:
145145
printk("NET_EVENT_IPV4_ADDR_ADD\n");
146+
k_poll_signal_raise(&self->done, WIFI_STATUS_CONN_SUCCESS);
146147
break;
147148
case NET_EVENT_SUPPLICANT_READY:
148149
printk("NET_EVENT_SUPPLICANT_READY\n");

ports/zephyr-cp/prj.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ CONFIG_WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_INF=y
3333
CONFIG_WIFI_NM_WPA_SUPPLICANT_THREAD_STACK_SIZE=12288
3434
# For wpa_supplicant use.
3535
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
36+
37+
CONFIG_DNS_RESOLVER=y
38+
CONFIG_DNS_RESOLVER_CACHE=y
39+
CONFIG_NET_IPV4=y
40+
CONFIG_NET_TCP=y
41+
CONFIG_DNS_SD=y
42+
CONFIG_NET_DHCPV4=y

0 commit comments

Comments
 (0)