Skip to content

Commit aa58c7e

Browse files
author
Daniel Campora
committed
cc3200: Append last 2 bytes of the MAC address to the default SSID.
1 parent b56634e commit aa58c7e

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

cc3200/mods/modwlan.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ void wlan_first_start (void) {
426426
}
427427

428428
modwlan_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

710720
STATIC 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
}

cc3200/mods/modwlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern _SlLockObj_t wlan_LockObj;
5555
******************************************************************************/
5656
extern void wlan_pre_init (void);
5757
extern modwlan_Status_t wlan_sl_enable (SlWlanMode_t mode, const char *ssid, uint8_t ssid_len, uint8_t sec,
58-
const char *key, uint8_t key_len, uint8_t channel);
58+
const char *key, uint8_t key_len, uint8_t channel, bool append_mac);
5959
extern void wlan_first_start (void);
6060
extern void wlan_update(void);
6161
extern void wlan_stop (uint32_t timeout);

cc3200/mptask.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ STATIC void mptask_init_sflash_filesystem (void) {
372372
}
373373

374374
STATIC void mptask_enter_ap_mode (void) {
375-
// enable simplelink in low power mode
375+
// enable simplelink in ap mode (use the MAC address to make the ssid unique)
376376
wlan_sl_enable (ROLE_AP, MICROPY_PORT_WLAN_AP_SSID, strlen(MICROPY_PORT_WLAN_AP_SSID), MICROPY_PORT_WLAN_AP_SECURITY,
377-
MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY), MICROPY_PORT_WLAN_AP_CHANNEL);
377+
MICROPY_PORT_WLAN_AP_KEY, strlen(MICROPY_PORT_WLAN_AP_KEY), MICROPY_PORT_WLAN_AP_CHANNEL, true);
378378
}
379379

380380
STATIC void mptask_create_main_py (void) {

docs/wipy/general.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ WLAN default behaviour
55
----------------------
66

77
When the WiPy boots with the default factory configuration starts in Access Point
8-
mode with ``ssid: wipy-wlan`` and ``key: www.wipy.io``.
8+
mode with ``ssid`` that starts with: ``wipy-wlan`` and ``key: www.wipy.io``.
99
Connect to this network and the WiPy will be reachable at ``192.168.1.1``. In order
1010
to gain access to the interactive prompt, open a telnet session to that IP address on
1111
the default port (23). You will be asked for credentials:
12-
``login: micro`` ``password: python``
12+
``login: micro`` and ``password: python``
1313

1414
Local file system and SD card
1515
-----------------------------
@@ -26,7 +26,7 @@ that should be located in the SD card.
2626
The file system is accessible via the native FTP server running in the WiPy.
2727
Open your FTP client of choice and connect to:
2828

29-
``ftp://192.168.1.1`` ``user: micro`` ``password: python``
29+
``ftp://192.168.1.1``, ``user: micro``, ``password: python``
3030

3131
Boot modes
3232
----------
@@ -75,5 +75,5 @@ There are currently 2 kinds of errors that you might see:
7575
1. If the heart beat LED flashes quickly, then a Python script(eg ``main.py``)
7676
has an error. Use the REPL to debug it.
7777
2. If the heart beat LED stays on, then there was a hard fault, you cannot
78-
recover from this, the only way out is by pressing the reset switch.
78+
recover from this, the only way out is to press the reset switch.
7979

0 commit comments

Comments
 (0)