summaryrefslogtreecommitdiff
path: root/shared-module/network
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module/network')
-rw-r--r--shared-module/network/__init__.c10
-rw-r--r--shared-module/network/__init__.h6
2 files changed, 14 insertions, 2 deletions
diff --git a/shared-module/network/__init__.c b/shared-module/network/__init__.c
index a674e8478..96648b260 100644
--- a/shared-module/network/__init__.c
+++ b/shared-module/network/__init__.c
@@ -43,6 +43,12 @@ void network_module_init(void) {
}
void network_module_deinit(void) {
+ for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
+ mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
+ mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
+ if (nic_type->deinit != NULL) nic_type->deinit(nic);
+ }
+ mp_obj_list_set_len(&MP_STATE_PORT(mod_network_nic_list), 0);
}
void network_module_background(void) {
@@ -93,3 +99,7 @@ void network_module_create_random_mac_address(uint8_t *mac) {
mac[4] = (uint8_t)(rb2 >> 8);
mac[5] = (uint8_t)(rb2);
}
+
+uint16_t network_module_create_random_source_tcp_port(void) {
+ return 0xc000 | shared_modules_random_getrandbits(14);
+}
diff --git a/shared-module/network/__init__.h b/shared-module/network/__init__.h
index 00a3c3957..f4eb05bb5 100644
--- a/shared-module/network/__init__.h
+++ b/shared-module/network/__init__.h
@@ -25,11 +25,12 @@
* THE SOFTWARE.
*/
-void network_module_create_random_mac_address(uint8_t *mac);
-
#ifndef MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
#define MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
+void network_module_create_random_mac_address(uint8_t *mac);
+uint16_t network_module_create_random_source_tcp_port(void);
+
#define MOD_NETWORK_IPADDR_BUF_SIZE (4)
#define MOD_NETWORK_AF_INET (2)
@@ -62,6 +63,7 @@ typedef struct _mod_network_nic_type_t {
int (*settimeout)(struct _mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno);
int (*ioctl)(struct _mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno);
void (*timer_tick)(struct _mod_network_socket_obj_t *socket);
+ void (*deinit)(struct _mod_network_socket_obj_t *socket);
} mod_network_nic_type_t;
typedef struct _mod_network_socket_obj_t {