Commit 67ecf55a authored by Madan Lanka's avatar Madan Lanka Committed by Uze Choi

[Easy-Setup] Arduino Enrollee Doxygen update and api folder change

- Reused OCConnectivityType struct instead of defining new struct
- Updated the Enrollee Device doxygen comments
- Enrollee EasySetup API folder is changed
- License header contribution year is updated

Change-Id: I72e095c5c886fb10dd365b72c80944f8864685ee
Signed-off-by: default avatarMadan Lanka <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3413Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent 58297daa
#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=== Prerequisites ===
* 1. Scons
......
#******************************************************************
#
# Copyright 2014 Samsung Electronics All Rights Reserved.
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
......@@ -65,8 +65,9 @@ if target_os == 'arduino':
'../../resource/csdk/stack/include',
'../../extlibs/cjson',
'sdk/enrollee/arduino/wifi',
'sdk/enrollee/common/src',
'sdk/enrollee/common/inc'])
'sdk/enrollee/api',
'sdk/enrollee/src',
'sdk/enrollee/inc'])
easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
......@@ -86,8 +87,8 @@ if target_os in ['android','linux']:
if target_os == 'arduino':
es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
['sdk/enrollee/common/src/easysetup.cpp',
'sdk/enrollee/common/src/resourceHandler.cpp',
['sdk/enrollee/src/easysetup.cpp',
'sdk/enrollee/src/resourceHandler.cpp',
'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
......
#******************************************************************
#
# Copyright 2014 Samsung Electronics All Rights Reserved.
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
......
#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
......@@ -33,8 +33,9 @@ enrollee_env.PrependUnique(CPPPATH = [
'../../../../../extlibs/cjson',
'../../../sdk/common',
'../../../sdk/enrollee/arduino/wifi',
'../../../sdk/enrollee/common/inc',
'../../../sdk/enrollee/common/src'
'../../../sdk/enrollee/api',
'../../../sdk/enrollee/inc',
'../../../sdk/enrollee/src'
])
enrollee_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
......
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -80,13 +80,13 @@ void setup()
OC_LOG_INIT();
OC_LOG(DEBUG, TAG, "OCServer is starting...");
if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) == ES_ERROR)
if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR)
{
OC_LOG(ERROR, TAG, "EasySetup Init Failed");
return;
}
if(InitProvisioning(EventCallbackInApp)== ES_ERROR)
if(InitProvisioning()== ES_ERROR)
{
OC_LOG(ERROR, TAG, "Init Provisioning Failed");
return;
......
#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
......
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -18,23 +18,63 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains SDK APIs for device operating in Enrollee Mode of EasySetup
*/
#ifndef EASYSETUP_ENROLLEE_H__
#define EASYSETUP_ENROLLEE_H__
// Do not remove the include below
#include "Arduino.h"
#include <string.h>
#include "ocstack.h"
#include "networkHandler.h"
typedef void (*EventCallback)(ESResult);
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/*
* Callback function for updating the Enrollee OnBoarding and Provisioning status result to the application
*
* @param esResult ESResult provides the current state of the Enrollee Device
*/
typedef void (*EventCallback)(ESResult esResult);
#ifdef ESWIFI
ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,EventCallback cb);
#endif
/**
* This function Initializes the EasySetup. This API must be called prior to invoking any other API
*
* @param networkType NetworkType on which OnBoarding has to be performed.
* @param ssid SSID of the target SoftAP network to which the Enrollee is connecting.
* @param passwd Password of the target SoftAP network to which the Enrollee is connecting
* @param eventCallback EventCallback for for updating the Enrollee OnBoarding and Provisioning status
* result to the application
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid,
const char *passwd,
EventCallback eventCallback);
#ifdef ESBLE
ESResult InitEasySetup(NetworkType networkType,EventCallback cb);
#endif
/**
* This function performs initialization of Provisioning and Network resources needed for EasySetup process.
*
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult InitProvisioning();
ESResult InitProvisioning(EventCallback cb);
/**
* This function performs termination of Provisioning and Network resources.
* Also terminates the IoTivity core stack.
*
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult TerminateEasySetup();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* EASYSETUP_ENROLLEE_H__ */
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -20,8 +20,29 @@
#include "networkHandler.h"
#define TAG "ES_NH"
// Arduino WiFi Shield includes
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <string.h>
#include "logger.h"
/**
* @var ES_NH_TAG
* @brief Logging tag for module name.
*/
#define ES_NH_TAG "ES_NH"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
static IPAddress myIP;
//-----------------------------------------------------------------------------
// Private internal function prototypes
//-----------------------------------------------------------------------------
int findNetwork(const char *ssid);
int ConnectToNetwork(const char *ssid, const char *pass);
void printEncryptionType(int thisType);
......@@ -29,11 +50,8 @@ void printEncryptionType(int thisType);
// Arduino WiFi Shield
// Note : Arduino WiFi Shield currently does NOT support multicast and therefore
// this server will NOT be listening on 224.0.1.187 multicast address.
static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0";
IPAddress myIP;
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
{
char *fwVersion;
......@@ -43,21 +61,21 @@ ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCa
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD)
{
OC_LOG(ERROR, TAG, "WiFi shield not present");
OC_LOG(ERROR, ES_NH_TAG, "WiFi shield not present");
return ES_ERROR;
}
// Verify that WiFi Shield is running the firmware with all UDP fixes
fwVersion = WiFi.firmwareVersion();
OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
OC_LOG_V(INFO, ES_NH_TAG, "WiFi Shield Firmware version %s", fwVersion);
if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER))
!= 0)
{
OC_LOG(DEBUG, TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
OC_LOG(DEBUG, ES_NH_TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
//return ES_ERROR;
}
OC_LOG_V(INFO, TAG, "Finding SSID: %s", ssid);
OC_LOG_V(INFO, ES_NH_TAG, "Finding SSID: %s", ssid);
while (findNetwork(ssid) == 0) // found
{
......@@ -126,17 +144,17 @@ int ConnectToNetwork(const char *ssid, const char *pass)
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
OC_LOG_V(INFO, ES_NH_TAG, "Attempting to connect to SSID: %s", ssid);
status = WiFi.begin((char *) ssid, (char *) pass);
// wait 10 seconds for connection:
delay(10000);
}
OC_LOG(DEBUG, TAG, "Connected to wifi");
OC_LOG(DEBUG, ES_NH_TAG, "Connected to wifi");
myIP = WiFi.localIP();
OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
OC_LOG_V(INFO, ES_NH_TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
char buf[50];
sprintf(buf, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
......@@ -145,20 +163,24 @@ int ConnectToNetwork(const char *ssid, const char *pass)
return 0;
}
int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info)
ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
{
if (targetType == ES_WIFI && WiFi.status() == WL_CONNECTED)
if (targetType == CT_ADAPTER_IP && WiFi.status() == WL_CONNECTED)
{
info->type = ES_WIFI;
info->type = CT_ADAPTER_IP;
info->ipaddr = WiFi.localIP();
if(strlen(WiFi.SSID())<=MAXSSIDLEN)
strcpy(info->ssid, WiFi.SSID());
else return -1;
return 0;
{
strcpy(info->ssid, WiFi.SSID());
return ES_OK;
}
else
{
return ES_ERROR;
}
}
return -1;
return ES_ERROR;
}
void printEncryptionType(int thisType)
......
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -18,48 +18,50 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains IP network handling functionality for Enrollee device
*/
#ifndef ES_NETWORK_HANDLER_H_
#define ES_NETWORK_HANDLER_H_
// Do not remove the include below
#include "Arduino.h"
#include "logger.h"
#include "ocstack.h"
#include <string.h>
// Arduino WiFi Shield
// Arduino WiFi Shield includes
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <string.h>
#include "logger.h"
#include "common.h"
#ifndef ES_NETWORK_HANDLER_H_
#define ES_NETWORK_HANDLER_H_
#define MAXSSIDLEN 33
#define MAXNETCREDLEN 20
#define MAXNUMTYPE 5
#define MAXADDRLEN 15
typedef void (*NetworkEventCallback)(ESResult);
/*
* Callback function for updating the Network status to the subscribers
*
* @param esResult ESResult provides the current state of the network connection status
*/
typedef void (*NetworkEventCallback)(ESResult esResult);
enum NetworkType
typedef struct
{
ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5
};
typedef struct NETWORKINFO
{
NetworkType type;
OCConnectivityType type;
// for WiFI
IPAddress ipaddr;
char ssid[MAXSSIDLEN];
// for BT, BLE
byte mac[6];
} NetworkInfo;
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info);
ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info);
#endif
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -21,10 +21,9 @@
// Do not remove the include below
#include "Arduino.h"
#include <string.h>
#include "logger.h"
#include "ocstack.h"
#include <string.h>
#include "common.h"
#include "networkHandler.h"
#include "octypes.h"
......
//******************************************************************
//
// Copyright 2014 Samsung Electronics All Rights Reserved.
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
......@@ -18,20 +18,48 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains the implementation for EasySetup Enrollee device
*/
#include "easysetup.h"
#include "logger.h"
#include "resourceHandler.h"
#define TAG "ES"
int g_eventflag = 0;
int g_cnt = 0;
char *targetSsid;
char *targetPass;
EventCallback g_cbForProvisioning = NULL;
EventCallback g_cbForOnboarding = NULL;
/**
* @var ES_ENROLLEE_TAG
* @brief Logging tag for module name.
*/
#define ES_ENROLLEE_TAG "ES"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
/**
* @var targetSsid
* @brief Target SSID of the Soft Access point to which the device has to connect
*/
static char *targetSsid;
/**
* @var targetPass
* @brief Password of the target access point to which the device has to connect
*/
static char *targetPass;
/**
* @var g_cbForEnrolleeStatus
* @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
*/
static EventCallback g_cbForEnrolleeStatus = NULL;
//-----------------------------------------------------------------------------
// Private internal function prototypes
//-----------------------------------------------------------------------------
void EventCallbackInOnboarding(ESResult event);
void EventCallbackInProvisioning(ESResult event);
......@@ -41,9 +69,9 @@ void EventCallbackInOnboarding(ESResult event)
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
if (g_cbForOnboarding != NULL)
if (g_cbForEnrolleeStatus != NULL)
{
g_cbForOnboarding(event);
g_cbForEnrolleeStatus(event);
}
}
}
......@@ -59,7 +87,7 @@ void EventCallbackInProvisioning(ESResult event)
if(TerminateEasySetup() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "Terminating stack failed");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "Terminating stack failed");
return;
}
......@@ -67,9 +95,9 @@ void EventCallbackInProvisioning(ESResult event)
res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
if (g_cbForProvisioning != NULL)
if (g_cbForEnrolleeStatus != NULL)
{
g_cbForProvisioning(res);
g_cbForEnrolleeStatus(res);
}
}
}
......@@ -78,14 +106,14 @@ void EventCallbackAfterProvisioning(ESResult event)
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
if (g_cbForProvisioning != NULL)
if (g_cbForEnrolleeStatus != NULL)
{
g_cbForProvisioning(event);
g_cbForEnrolleeStatus(event);
}
}
}
ESResult FindNetworkForOnboarding(NetworkType networkType,
ESResult FindNetworkForOnboarding(OCConnectivityType networkType,
const char *ssid,
const char *passwd,
EventCallback cb)
......@@ -95,20 +123,22 @@ ESResult FindNetworkForOnboarding(NetworkType networkType,
return ES_ERROR;
}
if (networkType == ES_WIFI)
if (networkType == CT_ADAPTER_IP)
{
if (g_cbForOnboarding == NULL)
if (g_cbForEnrolleeStatus == NULL)
{
g_cbForOnboarding = cb;
g_cbForEnrolleeStatus = cb;
}
if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED)
{
OC_LOG(ERROR, TAG, "ConnectToWiFiNetwork Failed");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Failed");
cb(ES_NETWORKNOTCONNECTED);
return ES_ERROR;
}
else{
OC_LOG(INFO, TAG, "ConnectToWiFiNetwork Success");
OC_LOG(INFO, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Success");
cb(ES_NETWORKCONNECTED);
return ES_OK;
}
}
......@@ -116,24 +146,24 @@ ESResult FindNetworkForOnboarding(NetworkType networkType,
}
ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid, const char *passwd,
EventCallback cb)
{
if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK)
{
OC_LOG(ERROR, TAG, "OnBoarding Failed");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "OnBoarding Failed");
return ES_ERROR;
}
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack init error");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack init error");
return ES_ERROR;
}
else
{
OC_LOG(DEBUG, TAG, "OCStack init success");
OC_LOG(DEBUG, ES_ENROLLEE_TAG, "OCStack init success");
return ES_OK;
}
}
......@@ -142,27 +172,18 @@ ESResult TerminateEasySetup()
{
if(OCStop() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack stop failed");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop failed");
return ES_ERROR;
}
else
{
OC_LOG(ERROR, TAG, "OCStack stop success");
OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop success");
return ES_OK;
}
}
ESResult InitProvisioning(EventCallback cb)
ESResult InitProvisioning()
{
if (cb == NULL)
{
return ES_ERROR;
}
else
{
g_cbForProvisioning = cb;
}
if (CreateProvisioningResource() != OC_STACK_OK)
{
return ES_ERROR;
......