|
34 | 34 | #include "py/obj.h" |
35 | 35 | #include "py/objstr.h" |
36 | 36 | #include "py/runtime.h" |
| 37 | +#include "inc/hw_types.h" |
| 38 | +#include "inc/hw_ints.h" |
| 39 | +#include "inc/hw_memmap.h" |
| 40 | +#include "rom_map.h" |
| 41 | +#include "prcm.h" |
| 42 | +#include "timeutils.h" |
37 | 43 | #include "netutils.h" |
38 | 44 | #include "modnetwork.h" |
39 | 45 | #include "modusocket.h" |
40 | 46 | #include "modwlan.h" |
41 | 47 | #include "pybioctl.h" |
| 48 | +#include "pybrtc.h" |
42 | 49 | #include "debug.h" |
43 | 50 | #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) |
44 | 51 | #include "serverstask.h" |
@@ -519,8 +526,13 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss |
519 | 526 | // set connection policy to Auto + Fast (tries to connect to the last connected AP) |
520 | 527 | ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1, 1, 0, 0, 0), NULL, 0)); |
521 | 528 | } |
| 529 | + |
| 530 | + // set current time and date (needed to validate certificates) |
| 531 | + wlan_set_current_time (pybrtc_get_seconds()); |
| 532 | + |
522 | 533 | // start the servers before returning |
523 | 534 | wlan_servers_start(); |
| 535 | + |
524 | 536 | return MODWLAN_OK; |
525 | 537 | } |
526 | 538 | return MODWLAN_ERROR_INVALID_PARAMS; |
@@ -562,6 +574,20 @@ bool wlan_is_connected (void) { |
562 | 574 | GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED)) || wlan_obj.staconnected); |
563 | 575 | } |
564 | 576 |
|
| 577 | +void wlan_set_current_time (uint32_t seconds_since_2000) { |
| 578 | + timeutils_struct_time_t tm; |
| 579 | + timeutils_seconds_since_2000_to_struct_time(seconds_since_2000, &tm); |
| 580 | + |
| 581 | + SlDateTime_t sl_datetime = {0}; |
| 582 | + sl_datetime.sl_tm_day = tm.tm_mday; |
| 583 | + sl_datetime.sl_tm_mon = tm.tm_mon; |
| 584 | + sl_datetime.sl_tm_year = tm.tm_year; |
| 585 | + sl_datetime.sl_tm_hour = tm.tm_hour; |
| 586 | + sl_datetime.sl_tm_min = tm.tm_min; |
| 587 | + sl_datetime.sl_tm_sec = tm.tm_sec; |
| 588 | + sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (_u8 *)(&sl_datetime)); |
| 589 | +} |
| 590 | + |
565 | 591 | //***************************************************************************** |
566 | 592 | // DEFINE STATIC FUNCTIONS |
567 | 593 | //***************************************************************************** |
@@ -900,6 +926,8 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *args) { |
900 | 926 | wlan_servers_start(); |
901 | 927 | } |
902 | 928 | } |
| 929 | + // set current time and date (needed to validate certificates) |
| 930 | + wlan_set_current_time (pybrtc_get_seconds()); |
903 | 931 | return mp_const_none; |
904 | 932 | } |
905 | 933 | } |
|
0 commit comments