@@ -426,7 +426,7 @@ void wlan_first_start (void) {
426426}
427427
428428modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode , const char * ssid , uint8_t ssid_len , uint8_t sec ,
429- const char * key , uint8_t key_len , uint8_t channel ) {
429+ const char * key , uint8_t key_len , uint8_t channel , bool append_mac ) {
430430
431431 if (mode == ROLE_STA || mode == ROLE_AP || mode == ROLE_P2P ) {
432432 // stop the servers
@@ -477,9 +477,14 @@ modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ss
477477 ASSERT (ssid != NULL && key != NULL );
478478 ASSERT_ON_ERROR (sl_WlanSet (SL_WLAN_CFG_GENERAL_PARAM_ID , WLAN_GENERAL_PARAM_OPT_AP_TX_POWER , sizeof (ucPower ),
479479 (unsigned char * )& ucPower ));
480- ASSERT_ON_ERROR (sl_WlanSet (SL_WLAN_CFG_AP_ID , WLAN_AP_OPT_SSID , ssid_len , (unsigned char * )ssid ));
481480 memcpy (wlan_obj .ssid , (unsigned char * )ssid , ssid_len );
482- wlan_obj .ssid [ssid_len ] = '\0' ;
481+ // append the last 2 bytes of the MAC address, since the use of this functionality is under our controll
482+ // we can assume that the lenght of the ssid is less than (32 - 5)
483+ if (append_mac ) {
484+ snprintf ((char * )& wlan_obj .ssid [ssid_len ], sizeof (wlan_obj .ssid ) - ssid_len , "-%02x%02x" , wlan_obj .mac [4 ], wlan_obj .mac [5 ]);
485+ ssid_len += 5 ;
486+ }
487+ ASSERT_ON_ERROR (sl_WlanSet (SL_WLAN_CFG_AP_ID , WLAN_AP_OPT_SSID , ssid_len , (unsigned char * )wlan_obj .ssid ));
483488 ASSERT_ON_ERROR (sl_WlanSet (SL_WLAN_CFG_AP_ID , WLAN_AP_OPT_SECURITY_TYPE , sizeof (uint8_t ), & sec ));
484489 ASSERT_ON_ERROR (sl_WlanSet (SL_WLAN_CFG_AP_ID , WLAN_AP_OPT_PASSWORD , key_len , (unsigned char * )key ));
485490 _u8 * country = (_u8 * )"EU" ;
@@ -687,24 +692,29 @@ STATIC mp_obj_t wlan_init_helper(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
687692 // get the ssid
688693 mp_uint_t ssid_len ;
689694 const char * ssid = mp_obj_str_get_data (args [1 ].u_obj , & ssid_len );
695+ if (ssid_len > 32 ) {
696+ goto arg_error ;
697+ }
690698
691699 // get the key
692700 mp_uint_t key_len ;
693701 const char * key = mp_obj_str_get_data (args [3 ].u_obj , & key_len );
694-
695702 if (key_len < 8 ) {
696- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , mpexception_value_invalid_arguments )) ;
703+ goto arg_error ;
697704 }
698705
699706 // force the channel to be between 1-11
700707 uint8_t channel = args [4 ].u_int ;
701708 channel = (channel > 0 && channel != 12 ) ? channel % 12 : 1 ;
702709
703- if (MODWLAN_OK != wlan_sl_enable (args [0 ].u_int , ssid , ssid_len , args [2 ].u_int , key , key_len , channel )) {
710+ if (MODWLAN_OK != wlan_sl_enable (args [0 ].u_int , ssid , ssid_len , args [2 ].u_int , key , key_len , channel , false )) {
704711 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_operation_failed ));
705712 }
706713
707714 return mp_const_none ;
715+
716+ arg_error :
717+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
708718}
709719
710720STATIC void wlan_lpds_callback_enable (mp_obj_t self_in ) {
@@ -750,7 +760,7 @@ STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
750760 }
751761 // TODO only STA mode supported for the moment. What if P2P?
752762 else if (n_args == 1 ) {
753- if (MODWLAN_OK != wlan_sl_enable (mode , NULL , 0 , 0 , NULL , 0 , 0 )) {
763+ if (MODWLAN_OK != wlan_sl_enable (mode , NULL , 0 , 0 , NULL , 0 , 0 , false )) {
754764 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_operation_failed ));
755765 }
756766 }
0 commit comments