Skip to content

Commit b90b69c

Browse files
committed
wip; compiles but doesn't link
1 parent 1d13e30 commit b90b69c

106 files changed

Lines changed: 3669 additions & 142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

devices/airlift/common-hal/socketpool/Socket.c

Lines changed: 710 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "py/obj.h"
10+
11+
#include "common-hal/socketpool/SocketPool.h"
12+
13+
typedef struct ssl_sslsocket_obj ssl_sslsocket_obj_t;
14+
15+
typedef struct {
16+
mp_obj_base_t base;
17+
int num;
18+
int type;
19+
int family;
20+
int ipproto;
21+
bool connected;
22+
socketpool_socketpool_obj_t *pool;
23+
ssl_sslsocket_obj_t *ssl_socket;
24+
mp_uint_t timeout_ms;
25+
} socketpool_socket_obj_t;
26+
27+
void socket_user_reset(void);
28+
// Unblock workflow socket select thread (platform specific)
29+
void socketpool_socket_poll_resume(void);
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/socketpool/SocketPool.h"
8+
#include "common-hal/socketpool/Socket.h"
9+
10+
#include "py/runtime.h"
11+
#include "shared-bindings/wifi/__init__.h"
12+
#include "common-hal/socketpool/__init__.h"
13+
14+
void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t *self, mp_obj_t radio) {
15+
// if (radio != MP_OBJ_FROM_PTR(&common_hal_wifi_radio_obj)) {
16+
// mp_raise_ValueError(MP_ERROR_TEXT("SocketPool can only be used with wifi.radio"));
17+
// }
18+
}
19+
20+
// common_hal_socketpool_socket is in socketpool/Socket.c to centralize open socket tracking.
21+
22+
// int socketpool_getaddrinfo_common(const char *host, int service, const struct addrinfo *hints, struct addrinfo **res) {
23+
// // As of 2022, the version of lwip in esp-idf does not handle the
24+
// // trailing-dot syntax of domain names, so emulate it.
25+
// // Remove this once https://github.com/espressif/esp-idf/issues/10013 has
26+
// // been implemented
27+
// if (host) {
28+
// size_t strlen_host = strlen(host);
29+
// if (strlen_host && host[strlen_host - 1] == '.') {
30+
// mp_obj_t nodot = mp_obj_new_str(host, strlen_host - 1);
31+
// host = mp_obj_str_get_str(nodot);
32+
// }
33+
// }
34+
35+
// char service_buf[6];
36+
// snprintf(service_buf, sizeof(service_buf), "%d", service);
37+
38+
// return lwip_getaddrinfo(host, service_buf, hints, res);
39+
// }
40+
41+
// static mp_obj_t format_address(const struct sockaddr *addr, int family) {
42+
// char ip_str[IPADDR_STRLEN_MAX]; // big enough for any supported address type
43+
// const struct sockaddr_in *a = (void *)addr;
44+
45+
// switch (family) {
46+
// #if CIRCUITPY_SOCKETPOOL_IPV6
47+
// case AF_INET6:
48+
// inet_ntop(family, &((const struct sockaddr_in6 *)a)->sin6_addr, ip_str, sizeof(ip_str));
49+
// break;
50+
// #endif
51+
// default:
52+
// case AF_INET:
53+
// inet_ntop(family, &((const struct sockaddr_in *)a)->sin_addr, ip_str, sizeof(ip_str));
54+
// break;
55+
// }
56+
// return mp_obj_new_str(ip_str, strlen(ip_str));
57+
// return mp_const_none;
58+
// }
59+
60+
// static mp_obj_t convert_sockaddr(const struct addrinfo *ai, int port) {
61+
// // #if CIRCUITPY_SOCKETPOOL_IPV6
62+
// // mp_int_t n_tuple = ai->ai_family == AF_INET6 ? 4 : 2;
63+
// // #else
64+
// // mp_int_t n_tuple = 2;
65+
// // #endif
66+
// // mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(n_tuple, NULL));
67+
// // result->items[0] = format_address(ai->ai_addr, ai->ai_family);
68+
// // result->items[1] = MP_OBJ_NEW_SMALL_INT(port);
69+
// // #if CIRCUITPY_SOCKETPOOL_IPV6
70+
// // if (ai->ai_family == AF_INET6) {
71+
// // const struct sockaddr_in6 *ai6 = (void *)ai->ai_addr;
72+
// // result->items[2] = MP_OBJ_NEW_SMALL_INT(ai6->sin6_flowinfo);
73+
// // result->items[3] = MP_OBJ_NEW_SMALL_INT(ai6->sin6_scope_id);
74+
// // }
75+
// // #endif
76+
// // return result;
77+
// return mp_const_none;
78+
// }
79+
80+
// static mp_obj_t convert_addrinfo(const struct addrinfo *ai, int port) {
81+
// // MP_STATIC_ASSERT(AF_INET == SOCKETPOOL_AF_INET);
82+
// // #if CIRCUITPY_SOCKETPOOL_IPV6
83+
// // MP_STATIC_ASSERT(AF_INET6 == SOCKETPOOL_AF_INET6);
84+
// // #endif
85+
// // // MP_STATIC_ASSERT(AF_UNSPEC == SOCKETPOOL_AF_UNSPEC);
86+
// // mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
87+
// // result->items[0] = MP_OBJ_NEW_SMALL_INT(ai->ai_family);
88+
// // result->items[1] = MP_OBJ_NEW_SMALL_INT(ai->ai_socktype);
89+
// // result->items[2] = MP_OBJ_NEW_SMALL_INT(ai->ai_protocol);
90+
// // result->items[3] = ai->ai_canonname ? mp_obj_new_str(ai->ai_canonname, strlen(ai->ai_canonname)) : MP_OBJ_NEW_QSTR(MP_QSTR_);
91+
// // result->items[4] = convert_sockaddr(ai, port);
92+
// // return result;
93+
// return mp_const_none;
94+
// }
95+
96+
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) {
97+
// const struct addrinfo hints = {
98+
// .ai_flags = flags,
99+
// .ai_family = family,
100+
// .ai_protocol = proto,
101+
// .ai_socktype = type,
102+
// };
103+
//
104+
// struct addrinfo *res = NULL;
105+
// int err = socketpool_getaddrinfo_common(host, port, &hints, &res);
106+
// if (err != 0 || res == NULL) {
107+
// common_hal_socketpool_socketpool_raise_gaierror_noname();
108+
// }
109+
//
110+
// nlr_buf_t nlr;
111+
// if (nlr_push(&nlr) == 0) {
112+
// mp_obj_t result = mp_obj_new_list(0, NULL);
113+
// for (struct addrinfo *ai = res; ai; ai = ai->ai_next) {
114+
// mp_obj_list_append(result, convert_addrinfo(ai, port));
115+
// }
116+
// nlr_pop();
117+
// lwip_freeaddrinfo(res);
118+
// return result;
119+
// } else {
120+
// lwip_freeaddrinfo(res);
121+
// nlr_raise(MP_OBJ_FROM_PTR(nlr.ret_val));
122+
// }
123+
return mp_const_none;
124+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "py/obj.h"
10+
11+
typedef struct {
12+
mp_obj_base_t base;
13+
} socketpool_socketpool_obj_t;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/socketpool/__init__.h"
8+
9+
#include "common-hal/socketpool/Socket.h"
10+
11+
void socketpool_user_reset(void) {
12+
// socket_user_reset();
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
struct addrinfo;
10+
11+
// int socketpool_getaddrinfo_common(const char *host, int service, const struct addrinfo *hints, struct addrinfo **res);
12+
// void socketpool_resolve_host_or_throw(int family, int type, const char *hostname, struct sockaddr_storage *addr, int port);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/ssl/SSLContext.h"
8+
#include "shared-bindings/ssl/SSLSocket.h"
9+
10+
#include "py/runtime.h"
11+
#include "py/stream.h"
12+
13+
void common_hal_ssl_sslcontext_construct(ssl_sslcontext_obj_t *self) {
14+
// common_hal_ssl_sslcontext_set_default_verify_paths(self);
15+
}
16+
17+
void common_hal_ssl_sslcontext_load_verify_locations(ssl_sslcontext_obj_t *self,
18+
const char *cadata) {
19+
// self->crt_bundle_attach = NULL;
20+
// self->use_global_ca_store = false;
21+
// self->cacert_buf = (const unsigned char *)cadata;
22+
// self->cacert_bytes = *cadata ? strlen(cadata) + 1 : 0;
23+
}
24+
25+
void common_hal_ssl_sslcontext_set_default_verify_paths(ssl_sslcontext_obj_t *self) {
26+
// self->crt_bundle_attach = crt_bundle_attach;
27+
// self->use_global_ca_store = true;
28+
// self->cacert_buf = NULL;
29+
// self->cacert_bytes = 0;
30+
}
31+
32+
bool common_hal_ssl_sslcontext_get_check_hostname(ssl_sslcontext_obj_t *self) {
33+
// return self->check_name;
34+
return false;
35+
}
36+
37+
void common_hal_ssl_sslcontext_set_check_hostname(ssl_sslcontext_obj_t *self, bool value) {
38+
// self->check_name = value;
39+
}
40+
41+
void common_hal_ssl_sslcontext_load_cert_chain(ssl_sslcontext_obj_t *self, mp_buffer_info_t *cert_buf, mp_buffer_info_t *key_buf) {
42+
// self->cert_buf = *cert_buf;
43+
// self->key_buf = *key_buf;
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "py/obj.h"
10+
11+
typedef struct {
12+
mp_obj_base_t base;
13+
bool check_name, use_global_ca_store;
14+
const unsigned char *cacert_buf;
15+
// size_t cacert_bytes;
16+
// int (*crt_bundle_attach)(mbedtls_ssl_config *conf);
17+
// mp_buffer_info_t cert_buf, key_buf;
18+
} ssl_sslcontext_obj_t;

0 commit comments

Comments
 (0)