Question on WIFI security enums

As I understand it, the security type for wireless can be one of the following:

typedef enum {
    WLAN_SEC_UNSEC = 0,
    WLAN_SEC_WEP,
    WLAN_SEC_WPA,
    WLAN_SEC_WPA2,
    WLAN_SEC_WPA_ENTERPRISE,
    WLAN_SEC_WPA2_ENTERPRISE,
    WLAN_SEC_NOT_SET = 0xFF
} WLanSecurityType;

I’m writing some code that I want to be able to be run on any platform that supports wireless and print out the various WIFI configuration parameters. The code I’ve written compiles with all of the Gen3 platforms but fails to compile on a Photon. Here is the snippet of code that fails when compiling on a Photon:

    for (int i = 0; i < found; i++) 
    {
        Serial.printf("Network: %d\n", i);
        Serial.print("  SSID: ");
        Serial.println(ap[i].ssid);
        // Security type
        Serial.print("  Security: ");
        switch (ap[i].security)
        {
            case WLAN_SEC_UNSEC:
                Serial.println("Open");
                break;
            case WLAN_SEC_WEP:
                Serial.println("WEP");
                break;
            case WLAN_SEC_WPA:
                Serial.println("WPA");
                break;
            case WLAN_SEC_WPA2:
                Serial.println("WPA2");
                break;
            case WLAN_SEC_WPA_ENTERPRISE:
                Serial.println("WPA Enterprise");
                break;
            case WLAN_SEC_WPA2_ENTERPRISE:
                Serial.println("WPA2 Enterprise");
                break;
            default:
                Serial.println("Unknown");
                break;
        }

When compiling on the Photon, I get the following error messages:

whoami.ino:129:18: 'WLAN_SEC_WPA_ENTERPRISE' was not declared in this scope
whoami.ino:132:18: 'WLAN_SEC_WPA2_ENTERPRISE' was not declared in this scope

These enum values must be firmware version dependent? When I compile on a 0.6.3 Photon, I get the error messages. When I compile on a 0.7.0 Photon, there are no errors.

Am I correct in assuming that if I want to be able to check for these enum values for all possible platforms, I need to check for a minimum firmware version of 0.7.0 before I can reference these enums?

Correct. WPA Enterprise support was added in 0.7.0, so you’ll need to add a check for the current version and not reference those two enum values if building for < 0.7.0.

#if SYSTEM_VERSION >= SYSTEM_VERSION_v070
// WLAN_SEC_WPA_ENTERPRISE and WLAN_SEC_WPA2_ENTERPRISE should be available
#endif // SYSTEM_VERSION >= SYSTEM_VERSION_v070

@avtolstoy Many thanks! Not only did you introduce me to the SYSTEM_VERSION variable, but you helped clean up some of my code.

@avtolstoy I wrapped the “offending” code as you suggested but I still get the same errors.

#if (SYSTEM_VERSION >= SYSTEM_VERSION_v070)
            case WLAN_SEC_WPA_ENTERPRISE:
                Serial.println("WPA Enterprise");
                break;
            case WLAN_SEC_WPA2_ENTERPRISE:
                Serial.println("WPA2 Enterprise");
                break;
#endif

If I compile on a 0.6.3 Photon, I get the errors. If I compile on a 0.7.0 Photon, everything is OK.

Ah, sorry about that. SYSTEM_VERSION_v070 will not be defined on 0.6.3, so that’s why the check fails.
You can

  1. define it manually
#ifndef SYSTEM_VERSION_v070
#define SYSTEM_VERSION_v070 0x00070000
#endif // SYSTEM_VERSION_v070
  1. change the check to
#ifdef SYSTEM_VERSION_v070
#endif // SYSTEM_VERSION_v070
  1. Or better yet, change the check to
#if defined(Wiring_WpaEnterprise) && Wiring_WpaEnterprise
#endif // defined(Wiring_WpaEnterprise) && Wiring_WpaEnterprise

I went with option #3.

1 Like