Microchip® Advanced Software Framework

wifi_provisioning.c File Reference

WiFi Provision Profile.

Copyright (c) 2017-2019 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <string.h>
#include "wifi_scan.h"
#include "at_ble_api.h"
#include "ble_manager.h"
#include "wifi_provisioning.h"
#include "ble_utils.h"

Macros

#define APPARAM_MULTIPART_LENGTH   (98)
 APPARAM being 98 bytes long (will be received from the remote device in multiple messages) More...
 
#define APPARAM_MULTIPART_PASS_POS   (APPARAM_MULTIPART_PASSLEN_POS + 1)
 
#define APPARAM_MULTIPART_PASSLEN_POS   (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH)
 
#define APPARAM_MULTIPART_SECTYPE_POS   (0)
 Position of various parameters within the 98 bytes. More...
 
#define APPARAM_MULTIPART_SSID_POS   (APPARAM_MULTIPART_SSIDLEN_POS + 1)
 
#define APPARAM_MULTIPART_SSIDLEN_POS   (APPARAM_MULTIPART_SECTYPE_POS + 1)
 
#define APPARAM_MULTIPART_TLSCERT_POS   (APPARAM_MULTIPART_TLSCERTLEN_POS+1)
 
#define APPARAM_MULTIPART_TLSCERTLEN_POS   (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH)
 
#define APPARAM_MULTIPART_TLSKEY_POS   (APPARAM_MULTIPART_TLSKEYLEN_POS+1)
 
#define APPARAM_MULTIPART_TLSKEYLEN_POS   (APPARAM_MULTIPART_TLSCERT_POS+WIFI_PROVISION_TLS_CERT_LENGTH)
 
#define APPARAM_MULTIPART_USERLEN_POS   (APPARAM_MULTIPART_PASS_POS + WIFI_PROVISION_MAX_PASS_LENGTH)
 
#define APPARAM_MULTIPART_USERNAME_POS   (APPARAM_MULTIPART_USERLEN_POS + 1)
 
#define NOTIFY_STATE_PROVISIONED   (2)
 
#define NOTIFY_STATE_PROVISIONFAILED   (0)
 
#define NOTIFY_STATE_WIFICONNECTING   (1)
 
#define PROVISION_PRINTF(...)   do{printf("\n\r* "); printf(__VA_ARGS__);}while(0)
 
#define PROVISION_PRINTF_CONT(...)   do{printf("\n\r* "); printf(__VA_ARGS__);}while(0)
 

Functions

void ble_connected (void)
 \ application updates ble has connected More...
 
void ble_disconnected (void)
 \ application updates ble has disconnected More...
 
uint8_t ble_is_connected (void)
 function for querying ble connect status More...
 
void disconnect_ble (void)
 \ brief application requests ble be disconnected More...
 
void inform_wifi_connection_state (uint8_t s)
 application updates wifi provisioning on wifi connect state More...
 
static at_ble_status_t prepare_advertisement (void)
 prepare advertisement data More...
 
at_ble_status_t provision_start (void)
 start or restart provision and advertise and get scan list More...
 
void register_wifi_provision_credentials_handler (wifi_provision_cred_callback_t credentials_fn)
 application to register the credential update function callback More...
 
void register_wifi_provision_scanning_handler (wifi_provision_scanning_callback_t scanning_fn)
 application to register the scanning function callback More...
 
void request_scan (void)
 application requests wifi scanning More...
 
static at_ble_status_t start_advertise (void)
 start advertising wifi provision service More...
 
uint8_t wifi_provision_char_changed_handler (at_ble_characteristic_changed_t *char_handle)
 service characteristic change handler function More...
 
at_ble_status_t wifi_provision_define (void)
 definition of WiFi Provision profile services More...
 
static uint8_t wifi_provision_get_state (void)
 return provision state More...
 
void wifi_provision_init (void *param)
 initialise wifi provision profile, includes all initialisation and start up More...
 
uint8_t wifi_provision_processing (void)
 application periodically kicks wifi provision processing More...
 
uint8_t wifi_provision_scanlist_receive (wifi_provision_scanlist *param)
 application updates the wifi scan list More...
 
static at_ble_status_t wifi_provision_scanmode_update (uint8_t sm)
 updating scan mode More...
 
static void wifi_provision_service_init (void)
 Initializations of profile services. More...
 
static void wifi_provision_set_state (uint8_t s)
 set the wifi provision state More...
 
uint8_t wifi_provision_svc_changed_handler (uint8_t *data)
 ble stack indicate service client configuration change More...
 

Variables

static uint8_t adv_scan_rsp_data [WIFI_PROVISION_ADV_SCAN_RESP_LEN]
 
at_ble_connected_t ble_connected_dev_info [MAX_DEVICE_CONNECTED]
 information of the connected devices More...
 
wifi_provision_cred_callback_t credentials_cb
 
static uint8_t is_BLE_Connected
 BLE connected or otherwise. More...
 
static uint8_t multi_part [APPARAM_MULTIPART_LENGTH]
 
wifi_provision_u8_callback_t provisioning_cb
 
wifi_provision_scanning_callback_t scanning_cb
 Callback handlers for connect and scan. More...
 
static uint8_t wifi_connection_state
 WiFi connection state that the app will inform on. More...
 
static uint8_t wifi_provision_state
 provisioning state More...
 
wificon_gatt_service_handler_t wificon_handle
 
wifiscan_gatt_service_handler_t wifiscan_handle
 

#define APPARAM_MULTIPART_LENGTH   (98)

APPARAM being 98 bytes long (will be received from the remote device in multiple messages)

Referenced by wifi_provision_char_changed_handler().

#define APPARAM_MULTIPART_PASS_POS   (APPARAM_MULTIPART_PASSLEN_POS + 1)
#define APPARAM_MULTIPART_PASSLEN_POS   (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH)
#define APPARAM_MULTIPART_SECTYPE_POS   (0)

Position of various parameters within the 98 bytes.

Referenced by wifi_provision_char_changed_handler().

#define APPARAM_MULTIPART_SSID_POS   (APPARAM_MULTIPART_SSIDLEN_POS + 1)
#define APPARAM_MULTIPART_SSIDLEN_POS   (APPARAM_MULTIPART_SECTYPE_POS + 1)
#define APPARAM_MULTIPART_TLSCERT_POS   (APPARAM_MULTIPART_TLSCERTLEN_POS+1)
#define APPARAM_MULTIPART_TLSCERTLEN_POS   (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH)
#define APPARAM_MULTIPART_TLSKEY_POS   (APPARAM_MULTIPART_TLSKEYLEN_POS+1)
#define APPARAM_MULTIPART_TLSKEYLEN_POS   (APPARAM_MULTIPART_TLSCERT_POS+WIFI_PROVISION_TLS_CERT_LENGTH)
#define APPARAM_MULTIPART_USERLEN_POS   (APPARAM_MULTIPART_PASS_POS + WIFI_PROVISION_MAX_PASS_LENGTH)
#define APPARAM_MULTIPART_USERNAME_POS   (APPARAM_MULTIPART_USERLEN_POS + 1)
#define NOTIFY_STATE_PROVISIONED   (2)
#define NOTIFY_STATE_PROVISIONFAILED   (0)
#define NOTIFY_STATE_WIFICONNECTING   (1)
#define PROVISION_PRINTF_CONT (   ...)    do{printf("\n\r* "); printf(__VA_ARGS__);}while(0)

void ble_connected ( void  )

\ application updates ble has connected

application updates ble has connected

References BLE_IS_CONNECTED, is_BLE_Connected, and PROVISION_PRINTF.

Referenced by ble_app_connected_update().

uint8_t ble_is_connected ( void  )

function for querying ble connect status

Returns
ble connected true or false

References is_BLE_Connected.

Referenced by provision_start(), and start_provisioning_app().

void disconnect_ble ( void  )

\ brief application requests ble be disconnected

application requests ble be disconnected

References at_ble_adv_stop(), at_ble_disconnect(), and AT_BLE_TERMINATED_BY_USER.

Referenced by provision_app_ble_disconnect().

void register_wifi_provision_credentials_handler ( wifi_provision_cred_callback_t  credentials_fn)

application to register the credential update function callback

Parameters
[in]application'scredential function

References credentials_cb.

Referenced by initialise_provisioning_app().

void register_wifi_provision_scanning_handler ( wifi_provision_scanning_callback_t  scanning_fn)

application to register the scanning function callback

Parameters
[in]application'sscanning function

References scanning_cb.

Referenced by initialise_provisioning_app().

void request_scan ( void  )

application requests wifi scanning

application requests wif scanning

References wifi_provision_set_state(), and WIFI_PROVISION_STATE_REQUESTING_SCAN.

uint8_t wifi_provision_char_changed_handler ( at_ble_characteristic_changed_t char_handle)

service characteristic change handler function

character changed handler

References APPARAM_MULTIPART_LENGTH, APPARAM_MULTIPART_PASS_POS, APPARAM_MULTIPART_PASSLEN_POS, APPARAM_MULTIPART_SECTYPE_POS, APPARAM_MULTIPART_SSID_POS, APPARAM_MULTIPART_SSIDLEN_POS, APPARAM_MULTIPART_TLSCERT_POS, APPARAM_MULTIPART_TLSCERTLEN_POS, APPARAM_MULTIPART_TLSKEY_POS, APPARAM_MULTIPART_TLSKEYLEN_POS, APPARAM_MULTIPART_USERLEN_POS, APPARAM_MULTIPART_USERNAME_POS, AT_BLE_SUCCESS, credentials_tls::certificate, credentials_tls::certificate_length, at_ble_characteristic_changed_t::char_len, at_ble_characteristic_changed_t::char_new_value, at_ble_characteristic_changed_t::char_offset, credentials_cb, FAILED_WIFICON_CHANGE_PARAM, FAILED_WIFISCAN_CHANGE_PARAM, INVALID_WIFICON_CHANGE_PARAM, credentials_tls::keydata, credentials_tls::keydata_length, multi_part, credentials::passphrase, credentials_mschapv2::passphrase, credentials::passphrase_length, credentials_mschapv2::passphrase_length, PROVISION_PRINTF, PROVISION_PRINTF_CONT, credentials::sec_type, credentials_tls::sec_type, credentials_mschapv2::sec_type, credentials::ssid, credentials_tls::ssid, credentials_mschapv2::ssid, credentials::ssid_length, credentials_tls::ssid_length, credentials_mschapv2::ssid_length, credentials_mschapv2::username, credentials_mschapv2::username_length, VALID_WIFICON_CHANGE_PARAM, VALID_WIFISCAN_CHANGE_PARAM, WIFI_PROVISION_MAX_PASS_LENGTH, WIFI_PROVISION_MAX_SSID_LENGTH, WIFI_PROVISION_MAX_USERNAME_LENGTH, WIFI_PROVISION_SCANMODE_SCANNING, wifi_provision_set_state(), WIFI_PROVISION_STATE_FAILED, WIFI_PROVISION_STATE_HAVE_CREDENTIAL, WIFI_PROVISION_STATE_REQUESTING_SCAN, WIFI_PROVISION_TLS_CERT_LENGTH, WIFI_PROVISION_TLS_KEY_LENGTH, wificon_char_change_apparam(), wificon_char_change_state_client_cfg(), and wifiscan_char_change_scanmode().

at_ble_status_t wifi_provision_define ( void  )

definition of WiFi Provision profile services

profile services definition to the attribute data base

References AT_BLE_SUCCESS, printf, wificon_primary_service_define(), and wifiscan_primary_service_define().

Referenced by wifi_provision_init().

static uint8_t wifi_provision_get_state ( void  )
static

return provision state

References wifi_provision_state.

Referenced by ble_disconnected(), and wifi_provision_processing().

void wifi_provision_init ( void *  param)

initialise wifi provision profile, includes all initialisation and start up

Initialize the profile, includes all initializations and start up routines of the profiles.

References BLE_IS_NOT_CONNECTED, is_BLE_Connected, wifi_provision_define(), wifi_provision_service_init(), wifi_provision_set_state(), and WIFI_PROVISION_STATE_IDLE.

uint8_t wifi_provision_processing ( void  )
static at_ble_status_t wifi_provision_scanmode_update ( uint8_t  sm)
static
static void wifi_provision_service_init ( void  )
static

Initializations of profile services.

References init_wifi_con_service(), and init_wifi_scan_service().

Referenced by wifi_provision_init().

uint8_t wifi_provision_svc_changed_handler ( uint8_t *  data)

ble stack indicate service client configuration change

Parameters
[in]servicechange data

References at_ble_characteristic_value_set(), AT_BLE_SUCCESS, s, and wificon_gatt_service_handler::serv_handle.

uint8_t adv_scan_rsp_data[WIFI_PROVISION_ADV_SCAN_RESP_LEN]
static

Referenced by prepare_advertisement().

information of the connected devices

uint8_t is_BLE_Connected
static

BLE connected or otherwise.

Referenced by ble_connected(), ble_disconnected(), ble_is_connected(), and wifi_provision_init().

uint8_t multi_part[APPARAM_MULTIPART_LENGTH]
static

Callback handlers for connect and scan.

Referenced by register_wifi_provision_scanning_handler(), and wifi_provision_processing().

uint8_t wifi_connection_state
static

WiFi connection state that the app will inform on.

Referenced by ble_disconnected(), inform_wifi_connection_state(), and provision_start().

uint8_t wifi_provision_state
static

provisioning state

Referenced by wifi_provision_get_state(), and wifi_provision_set_state().