summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorMark <56205165+gamblor21@users.noreply.github.com>2020-10-16 15:52:45 -0500
committerGitHub <noreply@github.com>2020-10-16 15:52:45 -0500
commit8e6d3e5b91f4c7cdb0dc4743a9a9937708daa624 (patch)
tree6d541d14808bd8456b17303fb654a73300f1adc5 /shared-bindings
parent645382d51d37a40312118eebc11da75639913fce (diff)
parentf0b37313c5adf2ad940d7279aa49620d36d7292d (diff)
Merge branch 'main' into recv_into_size_check6.1.0-alpha.0
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_bleio/CharacteristicBuffer.c2
-rw-r--r--shared-bindings/_bleio/Connection.c2
-rw-r--r--shared-bindings/_bleio/PacketBuffer.c2
-rw-r--r--shared-bindings/_bleio/__init__.c15
-rw-r--r--shared-bindings/_bleio/__init__.h2
-rw-r--r--shared-bindings/rgbmatrix/RGBMatrix.h2
-rw-r--r--shared-bindings/socketpool/Socket.c3
-rw-r--r--shared-bindings/socketpool/SocketPool.c3
-rw-r--r--shared-bindings/wifi/Radio.c48
-rw-r--r--shared-bindings/wifi/Radio.h4
-rw-r--r--shared-bindings/wifi/ScannedNetworks.c3
11 files changed, 53 insertions, 33 deletions
diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c
index 7bcbc807e..4d6c836c1 100644
--- a/shared-bindings/_bleio/CharacteristicBuffer.c
+++ b/shared-bindings/_bleio/CharacteristicBuffer.c
@@ -37,7 +37,7 @@
STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self) {
if (!common_hal_bleio_characteristic_buffer_connected(self)) {
- mp_raise_bleio_ConnectionError(translate("Not connected"));
+ mp_raise_ConnectionError(translate("Not connected"));
}
}
diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c
index b5eeaa906..fe82af098 100644
--- a/shared-bindings/_bleio/Connection.c
+++ b/shared-bindings/_bleio/Connection.c
@@ -63,7 +63,7 @@
void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
if (!common_hal_bleio_connection_get_connected(self)) {
- mp_raise_bleio_ConnectionError(translate("Connection has been disconnected and can no longer be used. Create a new connection."));
+ mp_raise_ConnectionError(translate("Connection has been disconnected and can no longer be used. Create a new connection."));
}
}
diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c
index 8c8970939..f2a3cbce0 100644
--- a/shared-bindings/_bleio/PacketBuffer.c
+++ b/shared-bindings/_bleio/PacketBuffer.c
@@ -161,7 +161,7 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_
// gatts write events, which may not have been sent yet.
//
// IDEAL:
- // mp_raise_bleio_ConnectionError(translate("Not connected"));
+ // mp_raise_ConnectionError(translate("Not connected"));
// TEMPORARY:
num_bytes_written = 0;
}
diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c
index 3d9084dd5..2ef70a64f 100644
--- a/shared-bindings/_bleio/__init__.c
+++ b/shared-bindings/_bleio/__init__.c
@@ -63,7 +63,6 @@
//| """Catchall exception for Bluetooth related errors."""
//| ...
MP_DEFINE_BLEIO_EXCEPTION(BluetoothError, Exception)
-
NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
@@ -71,18 +70,6 @@ NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* fmt, ...)
va_end(argptr);
nlr_raise(exception);
}
-//| class ConnectionError(BluetoothError):
-//| """Raised when a connection is unavailable."""
-//| ...
-//|
-MP_DEFINE_BLEIO_EXCEPTION(ConnectionError, bleio_BluetoothError)
-NORETURN void mp_raise_bleio_ConnectionError(const compressed_string_t* fmt, ...) {
- va_list argptr;
- va_start(argptr,fmt);
- mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_bleio_ConnectionError, fmt, argptr);
- va_end(argptr);
- nlr_raise(exception);
-}
//| class RoleError(BluetoothError):
//| """Raised when a resource is used as the mismatched role. For example, if a local CCCD is
@@ -93,6 +80,7 @@ MP_DEFINE_BLEIO_EXCEPTION(RoleError, bleio_BluetoothError)
NORETURN void mp_raise_bleio_RoleError(const compressed_string_t* msg) {
mp_raise_msg(&mp_type_bleio_RoleError, msg);
}
+
//| class SecurityError(BluetoothError):
//| """Raised when a security related error occurs."""
//| ...
@@ -183,7 +171,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
// Errors
{ MP_ROM_QSTR(MP_QSTR_BluetoothError), OBJ_FROM_PTR(&mp_type_bleio_BluetoothError) },
- { MP_ROM_QSTR(MP_QSTR_ConnectionError), OBJ_FROM_PTR(&mp_type_bleio_ConnectionError) },
{ MP_ROM_QSTR(MP_QSTR_RoleError), OBJ_FROM_PTR(&mp_type_bleio_RoleError) },
{ MP_ROM_QSTR(MP_QSTR_SecurityError), OBJ_FROM_PTR(&mp_type_bleio_SecurityError) },
diff --git a/shared-bindings/_bleio/__init__.h b/shared-bindings/_bleio/__init__.h
index 588b1f197..65ba9b3a5 100644
--- a/shared-bindings/_bleio/__init__.h
+++ b/shared-bindings/_bleio/__init__.h
@@ -51,14 +51,12 @@ const mp_obj_type_t mp_type_bleio_ ## exc_name = { \
};
extern const mp_obj_type_t mp_type_bleio_BluetoothError;
-extern const mp_obj_type_t mp_type_bleio_ConnectionError;
extern const mp_obj_type_t mp_type_bleio_RoleError;
extern const mp_obj_type_t mp_type_bleio_SecurityError;
extern mp_obj_t bleio_set_adapter(mp_obj_t adapter_obj);
NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* msg, ...);
-NORETURN void mp_raise_bleio_ConnectionError(const compressed_string_t* msg, ...);
NORETURN void mp_raise_bleio_RoleError(const compressed_string_t* msg);
NORETURN void mp_raise_bleio_SecurityError(const compressed_string_t* msg, ...);
diff --git a/shared-bindings/rgbmatrix/RGBMatrix.h b/shared-bindings/rgbmatrix/RGBMatrix.h
index 1dc5a406c..bfe37c340 100644
--- a/shared-bindings/rgbmatrix/RGBMatrix.h
+++ b/shared-bindings/rgbmatrix/RGBMatrix.h
@@ -27,7 +27,7 @@
#pragma once
#include "shared-module/rgbmatrix/RGBMatrix.h"
-#include "lib/protomatter/core.h"
+#include "lib/protomatter/src/core.h"
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c
index f4a1e636a..e7b31842d 100644
--- a/shared-bindings/socketpool/Socket.c
+++ b/shared-bindings/socketpool/Socket.c
@@ -36,8 +36,6 @@
#include "py/runtime.h"
#include "py/mperrno.h"
-static const char* TAG = "socket binding";
-
//| class Socket:
//| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call
//| `SocketPool.socket()`.
@@ -182,7 +180,6 @@ STATIC mp_obj_t socketpool_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
bool ok = common_hal_socketpool_socket_connect(self, host, hostlen, port);
if (!ok) {
- ESP_EARLY_LOGW(TAG, "socket connect failed");
mp_raise_OSError(0);
}
diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c
index 9f56e8c7e..527cf7e98 100644
--- a/shared-bindings/socketpool/SocketPool.c
+++ b/shared-bindings/socketpool/SocketPool.c
@@ -37,8 +37,6 @@
#include "shared-bindings/socketpool/Socket.h"
#include "shared-bindings/socketpool/SocketPool.h"
-static const char* TAG = "socketpool binding";
-
//| class SocketPool:
//| """A pool of socket resources available for the given radio. Only one
//| SocketPool can be created for each radio.
@@ -121,7 +119,6 @@ STATIC mp_obj_t socketpool_socketpool_getaddrinfo(size_t n_args, const mp_obj_t
}
if (ip_str == mp_const_none) {
- ESP_EARLY_LOGW(TAG, "no ip str");
mp_raise_OSError(0);
}
diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c
index 928f21da9..b548d66f6 100644
--- a/shared-bindings/wifi/Radio.c
+++ b/shared-bindings/wifi/Radio.c
@@ -24,11 +24,13 @@
* THE SOFTWARE.
*/
+#include "shared-bindings/wifi/__init__.h"
+
+#include <regex.h>
#include <string.h>
-#include "py/objproperty.h"
#include "py/runtime.h"
-#include "shared-bindings/wifi/__init__.h"
+#include "py/objproperty.h"
//| class Radio:
//| """Native wifi radio.
@@ -50,7 +52,6 @@
//|
STATIC mp_obj_t wifi_radio_get_enabled(mp_obj_t self) {
return mp_obj_new_bool(common_hal_wifi_radio_get_enabled(self));
-
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_enabled_obj, wifi_radio_get_enabled);
@@ -102,6 +103,45 @@ STATIC mp_obj_t wifi_radio_stop_scanning_networks(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_scanning_networks_obj, wifi_radio_stop_scanning_networks);
+//| hostname: ReadableBuffer
+//| """Hostname for wifi interface. When the hostname is altered after interface started/connected
+//| the changes would only be reflected once the interface restarts/reconnects."""
+//|
+STATIC mp_obj_t wifi_radio_get_hostname(mp_obj_t self_in) {
+ wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return common_hal_wifi_radio_get_hostname(self);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_hostname_obj, wifi_radio_get_hostname);
+
+STATIC mp_obj_t wifi_radio_set_hostname(mp_obj_t self_in, mp_obj_t hostname_in) {
+ mp_buffer_info_t hostname;
+ mp_get_buffer_raise(hostname_in, &hostname, MP_BUFFER_READ);
+
+ if (hostname.len < 1 || hostname.len > 253) {
+ mp_raise_ValueError(translate("Hostname must be between 1 and 253 characters"));
+ }
+
+ regex_t regex; //validate hostname according to RFC 1123
+ regcomp(&regex,"^(([a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]{0,61}[a-z0-9])$", REG_EXTENDED | REG_ICASE | REG_NOSUB);
+ if (regexec(&regex, hostname.buf, 0, NULL, 0)) {
+ mp_raise_ValueError(translate("invalid hostname"));
+ }
+ regfree(&regex);
+
+ wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ common_hal_wifi_radio_set_hostname(self, hostname.buf);
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_hostname_obj, wifi_radio_set_hostname);
+
+const mp_obj_property_t wifi_radio_hostname_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&wifi_radio_get_hostname_obj,
+ (mp_obj_t)&wifi_radio_set_hostname_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
//| def connect(self, ssid: ReadableBuffer, password: ReadableBuffer = b"", *, channel: Optional[int] = 0, timeout: Optional[float] = None) -> bool:
//| """Connects to the given ssid and waits for an ip address. Reconnections are handled
//| automatically once one connection succeeds."""
@@ -216,6 +256,8 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_start_scanning_networks), MP_ROM_PTR(&wifi_radio_start_scanning_networks_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop_scanning_networks), MP_ROM_PTR(&wifi_radio_stop_scanning_networks_obj) },
+ { MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&wifi_radio_hostname_obj) },
+
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) },
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h
index b5341d51c..a6a616154 100644
--- a/shared-bindings/wifi/Radio.h
+++ b/shared-bindings/wifi/Radio.h
@@ -35,7 +35,6 @@
const mp_obj_type_t wifi_radio_type;
-
typedef enum {
WIFI_RADIO_ERROR_NONE,
WIFI_RADIO_ERROR_UNKNOWN,
@@ -46,6 +45,9 @@ typedef enum {
extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self);
extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled);
+extern mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self);
+extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname);
+
extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);
diff --git a/shared-bindings/wifi/ScannedNetworks.c b/shared-bindings/wifi/ScannedNetworks.c
index d04f0f92a..9316faa45 100644
--- a/shared-bindings/wifi/ScannedNetworks.c
+++ b/shared-bindings/wifi/ScannedNetworks.c
@@ -32,8 +32,6 @@
#include "py/runtime.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
-static const char *TAG = "cp iternext";
-
//| class ScannedNetworks:
//| """Iterates over all `wifi.Network` objects found while scanning. This object is always created
//| by a `wifi.Radio`: it has no user-visible constructor."""
@@ -46,7 +44,6 @@ STATIC mp_obj_t scannednetworks_iternext(mp_obj_t self_in) {
return network;
}
- ESP_EARLY_LOGI(TAG, "stop iteration");
return MP_OBJ_STOP_ITERATION;
}