Wi-Fi NAN AT Commands

Note

  • The NAN AT commands are disabled by default.

  • Refer to Configure project (menuconfig) , enter CONFIG WIFI and select Enable NAN host control app (km4_tz / WHC host) to enable the NAN AT commands (this option automatically enables Enable NAN).

  • To enable the IPv6 data path (AT+NANDPIP=6), enter CONFIG LWIP and select Enable LWIP IPV6.

AT+NANSTART

Function Description

Initialize NAN and join or form a cluster

Note

NAN starts with auto_accept enabled: an incoming NDP request is answered automatically from the event context, and the NIK follow-up after SETUP is issued automatically (needed by peers with a short NDP timeout, e.g. iPhone).

Command Format

AT+NANSTART

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

AT+NANSTOP

Function Description

Stop NAN and release its resources

Command Format

AT+NANSTOP

Response Format

Successful Response:

OK

AT+NANPUB

Function Description

Publish a NAN service (as publisher)

Command Format

AT+NANPUB=name,<service_name>[,<type>,<value>……]

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Parameters

<type>:

parameter type, followed by the corresponding <value>

  • name: followed by the service name

  • id: followed by the publish ID

  • sec: followed by the security type

  • pmk: followed by the pre-shared key

  • pw: followed by the passphrase

  • bstrap: followed by the bootstrapping method

  • nik: followed by the NIK caching switch

  • gtk: followed by the GTK cipher switch

<value>:

the specific parameter for the corresponding <type>

name:

service name string (required)

id:

publish ID

  • Default: 1

sec:

security type

  • 0: open (default)

  • 1: pmk

  • 2: passphrase

  • 3: pairing

pmk:

pre-shared key

  • Length: 32 characters

  • Required when sec is 1

pw:

passphrase

  • Length: 1 to 16 characters

  • Required when sec is 2

bstrap:

bootstrapping method (enum nan_bstrap_method, bitmask, u8 field, only the low 8 bits are settable)

  • Only effective when sec is 3 (pairing); default 1 (opportunistic)

  • Each bit is a credential-exchange method; the two peers must form a compatible display↔keypad / display↔scan / tag↔reader pair, otherwise discovery silently fails

  • Common values (value / bit / meaning / role):

    • 1 (BIT0): opportunistic (no passphrase) —— symmetric, both peers set 1

    • 2 (BIT1): pin-code —— display side (show PIN)

    • 4 (BIT2): passphrase —— display side (show passphrase)

    • 6 (BIT1|BIT2): display (pin-code + passphrase) —— display side, used by the publisher in the iPhone case

    • 8 (BIT3): QR code —— display side (show QR code)

    • 16 (BIT4): NFC tag —— act as NFC tag

    • 32 (BIT5): pin-code —— keypad side (enter PIN)

    • 64 (BIT6): passphrase —— keypad side (enter passphrase)

    • 128 (BIT7): QR code —— scan side (camera scan)

nik:

NIK caching switch

  • 0: disabled

  • 1: enabled (default)

gtk:

GTK cipher switch

  • 0: disabled (default)

  • 1: enabled

Note

  • The <type>, <value> pairs can be arranged in any order and must appear in pairs (name and its value are required).

  • If a parameter is missing, the pairs are unbalanced, or an unknown <type> is given, the command usage help is printed first, then ERROR: -1 is returned.

  • Common bstrap pairings (only effective when sec is 3):

    • opportunistic: both peers set 1 and skip NANSETPW;

    • real iPhone: the publisher sets 6 (display) and the iPhone acts as keypad (user enters the PIN);

    • two-board pin-code pairing: one side sets 32 (keypad) and the other sets 2 (display).

AT+NANSUB

Function Description

Subscribe to a NAN service (as subscriber)

Command Format

AT+NANSUB=name,<service_name>[,<type>,<value>……]

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Parameters

<type>:

parameter type, followed by the corresponding <value>

  • name: followed by the service name

  • id: followed by the subscribe ID

  • sec: followed by the security type

  • pmk: followed by the pre-shared key

  • pw: followed by the passphrase

  • bstrap: followed by the bootstrapping method

  • nik: followed by the NIK caching switch

<value>:

the specific parameter for the corresponding <type>

name:

service name string (required)

id:

subscribe ID

  • Default: 1

sec:

security type

  • 0: open (default)

  • 1: pmk

  • 2: passphrase

  • 3: pairing

pmk:

pre-shared key

  • Length: 32 characters

  • Required when sec is 1

pw:

passphrase

  • Length: 1 to 16 characters

  • Required when sec is 2

bstrap:

bootstrapping method (enum nan_bstrap_method, bitmask, u8 field, only the low 8 bits are settable)

  • Only effective when sec is 3 (pairing); default 1 (opportunistic)

  • Each bit is a credential-exchange method; the two peers must form a compatible display↔keypad / display↔scan / tag↔reader pair, otherwise discovery silently fails

  • Common values (value / bit / meaning / role):

    • 1 (BIT0): opportunistic (no passphrase) —— symmetric, both peers set 1

    • 2 (BIT1): pin-code —— display side (show PIN)

    • 4 (BIT2): passphrase —— display side (show passphrase)

    • 6 (BIT1|BIT2): display (pin-code + passphrase) —— display side, used by the publisher in the iPhone case

    • 8 (BIT3): QR code —— display side (show QR code)

    • 16 (BIT4): NFC tag —— act as NFC tag

    • 32 (BIT5): pin-code —— keypad side (enter PIN)

    • 64 (BIT6): passphrase —— keypad side (enter passphrase)

    • 128 (BIT7): QR code —— scan side (camera scan)

nik:

NIK caching switch

  • 0: disabled

  • 1: enabled (default)

Note

  • The <type>, <value> pairs can be arranged in any order and must appear in pairs (name and its value are required).

  • If a parameter is missing, the pairs are unbalanced, or an unknown <type> is given, the command usage help is printed first, then ERROR: -1 is returned.

  • Common bstrap pairings (only effective when sec is 3):

    • opportunistic: both peers set 1 and skip NANSETPW;

    • real iPhone: the publisher sets 6 (display) and the iPhone acts as keypad (user enters the PIN);

    • two-board pin-code pairing: one side sets 32 (keypad) and the other sets 2 (display).

AT+NANSETPW

Function Description

Set the passphrase used for pairing. If a peer has already been discovered (latched), it applies to that peer; otherwise it serves as the global default passphrase.

Command Format

AT+NANSETPW=<passphrase>

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Parameters

<passphrase>:

the passphrase used for pairing

Note

The AT layer does not validate the length of <passphrase> (unlike pw in NANPUB/NANSUB); the length constraint is determined by the underlying API.

AT+NANBSTRAPREQ

Function Description

The subscriber initiates the bootstrapping handshake

Command Format

AT+NANBSTRAPREQ

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

AT+NANPAIR

Function Description

The initiator starts NAN pairing (PASN)

Command Format

AT+NANPAIR[=verification]

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Parameters

verification:

pairing type

  • without argument: setup pairing (default)

  • verification: verification pairing

AT+NANDPREQ

Function Description

The subscriber initiates a data path to the publisher

Command Format

AT+NANDPREQ

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

AT+NANDPRSP

Function Description

The publisher accepts a data-path request

Command Format

AT+NANDPRSP

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Note

With auto_accept enabled, the responder has already answered from the event context, so this command is idempotent.

AT+NANDPEND

Function Description

Tear down a data path

Command Format

AT+NANDPEND[=<ndp_id>]

Response Format

Successful Response:

OK

Parameters

<ndp_id>:

the NDP ID to tear down

  • Default: 0 (the last ndp-id)

AT+NANDPIP

Function Description

Bring up the L3 network interface over the data path

Command Format

AT+NANDPIP[=<4/6>]

Response Format

Successful Response:

OK

Error Response:

ERROR: -1

Parameters

<4/6>:

IP version

  • 4: static IPv4 with static ARP (default)

  • 6: IPv6 link-local (EUI-64) with static neighbor

Note

  • Only 6 selects IPv6; the default or any value other than 6 is treated as IPv4.

  • Using 6 requires CONFIG_LWIP_IPV6 to be enabled at build time.