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"
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) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_PASSLEN_POS (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH) |
Referenced by wifi_provision_char_changed_handler().
#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) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_SSIDLEN_POS (APPARAM_MULTIPART_SECTYPE_POS + 1) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_TLSCERT_POS (APPARAM_MULTIPART_TLSCERTLEN_POS+1) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_TLSCERTLEN_POS (APPARAM_MULTIPART_SSID_POS + WIFI_PROVISION_MAX_SSID_LENGTH) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_TLSKEY_POS (APPARAM_MULTIPART_TLSKEYLEN_POS+1) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_TLSKEYLEN_POS (APPARAM_MULTIPART_TLSCERT_POS+WIFI_PROVISION_TLS_CERT_LENGTH) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_USERLEN_POS (APPARAM_MULTIPART_PASS_POS + WIFI_PROVISION_MAX_PASS_LENGTH) |
Referenced by wifi_provision_char_changed_handler().
#define APPARAM_MULTIPART_USERNAME_POS (APPARAM_MULTIPART_USERLEN_POS + 1) |
Referenced by wifi_provision_char_changed_handler().
#define NOTIFY_STATE_PROVISIONED (2) |
Referenced by inform_wifi_connection_state().
#define NOTIFY_STATE_PROVISIONFAILED (0) |
Referenced by inform_wifi_connection_state().
#define NOTIFY_STATE_WIFICONNECTING (1) |
Referenced by inform_wifi_connection_state().
#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) |
Referenced by wifi_provision_char_changed_handler().
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().
void ble_disconnected | ( | void | ) |
\ application updates ble has disconnected
application updates ble has disconnected
References BLE_IS_NOT_CONNECTED, is_BLE_Connected, PROVISION_PRINTF, wifi_connection_state, WIFI_CONNECTION_STATE_PROVISIONFAILED, wifi_provision_get_state(), wifi_provision_set_state(), WIFI_PROVISION_STATE_FAILED, and WIFI_PROVISION_STATE_IDLE.
Referenced by ble_app_disconnected_update().
uint8_t ble_is_connected | ( | void | ) |
function for querying ble connect status
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 inform_wifi_connection_state | ( | uint8_t | s | ) |
application updates wifi provisioning on wifi connect state
[in] | wifi | connect state |
References NOTIFY_STATE_PROVISIONED, NOTIFY_STATE_PROVISIONFAILED, NOTIFY_STATE_WIFICONNECTING, PROVISION_PRINTF, wifi_connection_state, WIFI_CONNECTION_STATE_CONNECTING, WIFI_CONNECTION_STATE_PROVISIONED, WIFI_CONNECTION_STATE_PROVISIONFAILED, wifi_provision_set_state(), WIFI_PROVISION_STATE_FAILED, WIFI_PROVISION_STATE_IDLE, and wificon_connect_noti().
Referenced by wifi_state_update().
|
static |
prepare advertisement data
References adv_scan_rsp_data, at_ble_adv_data_set(), AT_BLE_FAILURE, AT_BLE_SUCCESS, PROVISION_PRINTF, WIFI_CON_SERVICE_UUID, WIFI_PROVISION_ADV_DATA_NAME_DATA, WIFI_PROVISION_ADV_DATA_NAME_LEN, WIFI_PROVISION_ADV_DATA_NAME_TYPE, WIFI_PROVISION_ADV_SCAN_RESP_LEN, WIFI_PROVISION_SCP_TYPE_MORE_128_BIT_UUID, and WIFICON_UUID_128_LEN.
Referenced by provision_start().
at_ble_status_t provision_start | ( | void | ) |
start or restart provision and advertise and get scan list
References AT_BLE_SUCCESS, ble_is_connected(), BLE_IS_NOT_CONNECTED, prepare_advertisement(), start_advertise(), wifi_connection_state, WIFI_CONNECTION_STATE_NOTSTARTED, wifi_provision_set_state(), WIFI_PROVISION_STATE_IDLE, and WIFI_PROVISION_STATE_REQUESTING_SCAN.
Referenced by start_provisioning_app().
void register_wifi_provision_credentials_handler | ( | wifi_provision_cred_callback_t | credentials_fn | ) |
application to register the credential update function callback
[in] | application's | credential 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
[in] | application's | scanning 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.
|
static |
start advertising wifi provision service
References AT_BLE_ADV_FP_ANY, AT_BLE_ADV_GEN_DISCOVERABLE, at_ble_adv_start(), AT_BLE_ADV_TYPE_UNDIRECTED, AT_BLE_FAILURE, AT_BLE_GAP_PERIPHERAL_SLV, at_ble_set_dev_config(), AT_BLE_SUCCESS, NULL, PROVISION_PRINTF, WIFI_PROVISION_ADV_DATA_NAME_DATA, WIFI_PROVISION_ADV_TIMEOUT, and WIFI_PROVISION_FAST_ADV.
Referenced by provision_start().
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, wificon_primary_service_define(), and wifiscan_primary_service_define().
Referenced by wifi_provision_init().
|
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 | ) |
application periodically kicks wifi provision processing
References AT_BLE_SUCCESS, scanning_cb, wifi_provision_get_state(), WIFI_PROVISION_SCANMODE_SCANNING, wifi_provision_scanmode_update(), wifi_provision_set_state(), WIFI_PROVISION_STATE_REQUESTING_SCAN, and WIFI_PROVISION_STATE_WIFI_SCANNING.
Referenced by provisioning_app_processing().
uint8_t wifi_provision_scanlist_receive | ( | wifi_provision_scanlist * | param | ) |
application updates the wifi scan list
[in] | wifi | scanlist |
References AT_BLE_SUCCESS, PROVISION_PRINTF, status, WIFI_PROVISION_SCANMODE_DONE, wifi_provision_scanmode_update(), wifi_provision_set_state(), WIFI_PROVISION_STATE_IN_PROGRESS, WIFI_PROVISION_STATE_REQUESTING_SCAN, and wifiscan_scanlist_receive().
Referenced by send_scan_result().
|
static |
updating scan mode
References wifiscan_update_scanmode_char_value().
Referenced by wifi_provision_processing(), and wifi_provision_scanlist_receive().
|
static |
Initializations of profile services.
References init_wifi_con_service(), and init_wifi_scan_service().
Referenced by wifi_provision_init().
|
static |
set the wifi provision state
References wifi_provision_state, WIFI_PROVISION_STATE_FAILED, WIFI_PROVISION_STATE_HAVE_CREDENTIAL, WIFI_PROVISION_STATE_IDLE, WIFI_PROVISION_STATE_IN_PROGRESS, WIFI_PROVISION_STATE_REQUESTING_SCAN, and WIFI_PROVISION_STATE_WIFI_SCANNING.
Referenced by ble_disconnected(), inform_wifi_connection_state(), provision_start(), request_scan(), wifi_provision_char_changed_handler(), wifi_provision_init(), wifi_provision_processing(), and wifi_provision_scanlist_receive().
uint8_t wifi_provision_svc_changed_handler | ( | uint8_t * | data | ) |
ble stack indicate service client configuration change
[in] | service | change data |
References at_ble_characteristic_value_set(), AT_BLE_SUCCESS, and wificon_gatt_service_handler::serv_handle.
|
static |
Referenced by prepare_advertisement().
at_ble_connected_t ble_connected_dev_info[MAX_DEVICE_CONNECTED] |
information of the connected devices
wifi_provision_cred_callback_t credentials_cb |
Referenced by register_wifi_provision_credentials_handler(), and wifi_provision_char_changed_handler().
|
static |
BLE connected or otherwise.
Referenced by ble_connected(), ble_disconnected(), ble_is_connected(), and wifi_provision_init().
|
static |
Referenced by wifi_provision_char_changed_handler().
wifi_provision_u8_callback_t provisioning_cb |
wifi_provision_scanning_callback_t scanning_cb |
Callback handlers for connect and scan.
Referenced by register_wifi_provision_scanning_handler(), and wifi_provision_processing().
|
static |
WiFi connection state that the app will inform on.
Referenced by ble_disconnected(), inform_wifi_connection_state(), and provision_start().
|
static |
provisioning state
Referenced by wifi_provision_get_state(), and wifi_provision_set_state().
wificon_gatt_service_handler_t wificon_handle |
wifiscan_gatt_service_handler_t wifiscan_handle |