Import('env')
+transport = env.get('TARGET_TRANSPORT')
+
env.AppendUnique(CPPDEFINES = ['EASY_SETUP_CA_INIT'])
easy_setup_env = env.Clone()
+#
target_os = env.get('TARGET_OS')
lib_env = env.Clone()
easy_setup_env.AppendUnique(LIBS = ['log'])
else:
easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
-
if target_os == 'arduino':
- easy_setup_env.AppendUnique(CPPPATH = [
+ if 'BLE' in transport:
+ easy_setup_env.AppendUnique(CPPPATH = [
'../../resource/oc_logger/include',
'../../resource/csdk/logger/include',
'../../resource/csdk/stack/include',
'../../extlibs/cjson',
- 'sdk/enrollee/arduino/wifi',
- 'sdk/enrollee/common/src',
+ 'sdk/enrollee/arduino/ble',
+ 'sdk/enrollee/common/src',
'sdk/enrollee/common/inc'])
-
+ easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESBLE'])
+ else:
+ easy_setup_env.AppendUnique(CPPPATH = [
+ '../../resource/oc_logger/include',
+ '../../resource/csdk/logger/include',
+ '../../resource/csdk/stack/include',
+ '../../extlibs/cjson',
+ 'sdk/enrollee/arduino/wifi',
+ 'sdk/enrollee/common/src',
+ 'sdk/enrollee/common/inc'])
+ easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
######################################################################
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/arduino/wifi/networkHandler.cpp'])
+ if 'BLE' in transport:
+ es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
+ ['sdk/enrollee/common/src/easysetupble.cpp',
+ 'sdk/enrollee/common/src/resourceHandler.cpp'])
+ else:
+ es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
+ ['sdk/enrollee/common/src/easysetup.cpp',
+ 'sdk/enrollee/common/src/resourceHandler.cpp',
+ 'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
-
if target_os == 'android':
- es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
- ['sdk/mediator/src/easysetupmgr.cpp',
- 'sdk/mediator/src/camutex_pthreads.c',
- 'sdk/mediator/src/provisioninghandler.cpp'])
+ if 'BLE' in transport:
+ es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
+ ['sdk/mediator/src/easysetupmgr.cpp',
+ 'sdk/mediator/src/camutex_pthreads.c',
+ 'sdk/mediator/src/provisioninghandler_ble.cpp'])
+ else :
+ es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
+ ['sdk/mediator/src/easysetupmgr.cpp',
+ 'sdk/mediator/src/camutex_pthreads.c',
+ 'sdk/mediator/src/provisioninghandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
if target_os == 'linux':
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.iotivity.service.easysetup"
android:versionCode="1"
- android:versionName="1.0" >
- <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
- <uses-permission android:name="android.permission.BLUETOOTH"/>
- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+ android:versionName="1.0">
+
+ <uses-feature
+ android:name="android.hardware.bluetooth_le"
+ android:required="true" />
+
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
- android:label="@string/app_name" >
+ android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
+
+ <activity android:name=".BLEActivity" />
+ <activity android:name=".OnBoardingSelect">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
}
public WiFiProvConfig getEnrollerWifiConfig() {
+ // SET the wifi credentials here
mWiFiProvConfig = new WiFiProvConfig("linksysy", "12345678");
return mWiFiProvConfig;
}
public BLEOnBoardingConfig getOnBoardingWifiConfig() {
- //TODO : Check proper configuration
+ // Set the uuid of the OIC device here
bleOnBoardingConfig = new BLEOnBoardingConfig();
-
bleOnBoardingConfig.setUuid("ade3d529-c784-4f63-a987-eb69f70ee816");
return bleOnBoardingConfig;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// User chose not to enable Bluetooth.
if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) {
- Log.e("error enablg bluetooth", resultCode + "");
+ Log.e("error bluetooth", "Bluetooth not enabled..Try again");
+ Toast.makeText(BLEActivity.this, "Bluetooth not enabled..Try again", Toast.LENGTH_SHORT).show();
finish();
return;
} else try {
public void start() {
//This function starts the bluetooth adpater so that the easysetup can start scanning for BLE devices
- //IF bluetooth is directly enabled it will directly start the setup of enrollee devices
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
if (!mBluetoothAdapter.isEnabled()) {
+ //Bluetooth is disabled, enable it
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} else try {
+ //IF bluetooth is directly enabled it will directly start the setup of enrollee devices
mEasySetupService.startSetup(mDevice);
} catch (IOException e) {
e.printStackTrace();
--- /dev/null
+package org.iotivity.service.easysetup;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.RadioButton;
+import android.widget.Toast;
+
+public class OnBoardingSelect extends Activity {
+
+ RadioButton radio_wifi, radio_ble;
+ Button button_continue;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_on_boarding_select);
+
+ radio_wifi = (RadioButton) findViewById(R.id.radioWifi);
+ radio_ble = (RadioButton) findViewById(R.id.radioBle);
+ button_continue = (Button) findViewById(R.id.button_continue);
+
+ button_continue.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent;
+ if (radio_wifi.isChecked())
+ intent = new Intent(OnBoardingSelect.this, MainActivity.class);
+ else if (radio_ble.isChecked())
+ intent = new Intent(OnBoardingSelect.this, BLEActivity.class);
+ else {
+
+ Toast.makeText(OnBoardingSelect.this, "Please Select OnBoarding method " +
+ "before Continuing", Toast.LENGTH_SHORT).show();
+ return;
+ }
+ startActivity(intent);
+ }
+ });
+ }
+
+
+}
--- /dev/null
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/background"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="org.iotivity.service.easysetup.BLEActivity">
+
+ <TextView
+ android:id="@+id/textView_ble"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/hello_world" />
+
+</RelativeLayout>
--- /dev/null
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/background"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="org.iotivity.service.easysetup.OnBoardingSelect">
+
+ <RadioGroup
+ android:id="@+id/radiotype"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="75dp">
+
+ <RadioButton
+ android:id="@+id/radioWifi"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:checked="true"
+ android:text="Soft AP/WIFI" />
+
+ <RadioButton
+ android:id="@+id/radioBle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="BLE" />
+
+ </RadioGroup>
+
+ <Button
+ android:id="@+id/button_continue"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
+ android:text="Continue" />
+
+
+</RelativeLayout>
--- /dev/null
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:context="org.iotivity.service.easysetup.BLEActivity">
+ <item
+ android:id="@+id/action_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="@string/action_settings" />
+</menu>
Import('env')
thinserver_env = env.Clone()
+transport = thinserver_env.get('TARGET_TRANSPORT')
+
######################################################################
# Build flags
######################################################################
-thinserver_env.PrependUnique(CPPPATH = [
+if 'BLE' in transport:
+ thinserver_env.PrependUnique(CPPPATH = [
+ '../../../../../resource/oc_logger/include',
+ '../../../../../resource/csdk/logger/include',
+ '../../../../../resource/csdk/stack/include',
+ '../../../../../extlibs/cjson',
+ '../../../sdk/common',
+ '../../../sdk/enrollee/arduino/ble',
+ '../../../sdk/enrollee/common/inc',
+ '../../../sdk/enrollee/common/src'
+ ])
+ thinserver_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESBLE'])
+else :
+ thinserver_env.PrependUnique(CPPPATH = [
'../../../../../resource/oc_logger/include',
'../../../../../resource/csdk/logger/include',
'../../../../../resource/csdk/stack/include',
'../../../sdk/enrollee/common/inc',
'../../../sdk/enrollee/common/src'
])
-
+ thinserver_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
+
thinserver_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-thinserver_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ARDUINOWIFI'])
thinserver_env.PrependUnique(LIBS = ['octbstack','ocsrm','connectivity_abstraction','coap', 'ESSDKLibrary'])
-
-thinserver = thinserver_env.Program('thinserver', 'thinserver.cpp')
+if 'BLE' in transport:
+ thinserver = thinserver_env.Program('thinserver', 'thinserverble.cpp')
+else :
+ thinserver = thinserver_env.Program('thinserver', 'thinserver.cpp')
env.CreateBin('thinserver')
i_thinserver = thinserver_env.Install(env.get('BUILD_DIR'), thinserver)
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+#include "logger.h"
+#include <string.h>
+#include "easysetup.h"
+
+const char *getResult(OCStackResult result);
+
+PROGMEM const char TAG[] = "ThinServer";
+
+void EventCallbackInApp(ESResult eventFlag)
+{
+ Serial.println("callback!!! in app");
+}
+
+// On Arduino Atmel boards with Harvard memory architecture, the stack grows
+// downwards from the top and the heap grows upwards. This method will print
+// the distance(in terms of bytes) between those two.
+// See here for more details :
+// http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
+void PrintArduinoMemoryStats()
+{
+#ifdef ARDUINO_AVR_MEGA2560
+ //This var is declared in avr-libc/stdlib/malloc.c
+ //It keeps the largest address not allocated for heap
+ extern char *__brkval;
+ //address of tmp gives us the current stack boundry
+ int tmp;
+ OC_LOG_V(INFO, TAG, "Stack: %u Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
+ OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
+ ((unsigned int)&tmp - (unsigned int)__brkval));
+#endif
+}
+//The setup function is called once at startup of the sketch
+void setup()
+{
+ // Add your initialization code here
+ // Note : This will initialize Serial port on Arduino at 115200 bauds
+ OC_LOG_INIT();
+ OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
+
+ if (InitEasySetup(ES_BLE, EventCallbackInApp) == ES_ERROR)
+ {
+ OC_LOG(ERROR, TAG, "EasySetup Init Failed");
+ return;
+ }
+
+ if (InitProvisioning(EventCallbackInApp) == ES_ERROR)
+ {
+ OC_LOG(ERROR, TAG, "Init Provisioning Failed");
+ return;
+ }
+}
+
+// The loop function is called in an endless loop
+void loop()
+{
+ // This artificial delay is kept here to avoid endless spinning
+ // of Arduino microcontroller. Modify it as per specific application needs.
+ delay(2000);
+
+ // This call displays the amount of free SRAM available on Arduino
+ PrintArduinoMemoryStats();
+
+ // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff
+ if (OCProcess() != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("OCStack process error"));
+ return;
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include "logger.h"
+#include "ocstack.h"
+#include <string.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);
+
+enum NetworkType
+{
+ ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5
+};
+typedef struct NETWORKINFO
+{
+ NetworkType type;
+ byte mac[6];
+} NetworkInfo;
+
+#endif
typedef void (*EventCallback)(ESResult);
-ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
- EventCallback cb);
+#ifdef ESWIFI
+ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,EventCallback cb);
+#endif
+
+#ifdef ESBLE
+ESResult InitEasySetup(NetworkType networkType,EventCallback cb);
+#endif
+
ESResult InitProvisioning(EventCallback cb);
ESResult TerminateEasySetup();
} NetResource;
OCStackResult CreateProvisioningResource();
+
+//created only for in case of wifi
+#ifdef ESWIFI
OCStackResult CreateNetworkResource();
+#endif
+
void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterResourceEventCallBack(ResourceEventCallback);
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#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;
+
+void EventCallbackInOnboarding(ESResult event);
+void EventCallbackInProvisioning(ESResult event);
+void EventCallbackAfterProvisioning(ESResult event);
+
+void EventCallbackInOnboarding(ESResult event)
+{
+ if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
+ {
+ if (g_cbForOnboarding != NULL)
+ {
+ g_cbForOnboarding(event);
+ }
+ }
+}
+
+void EventCallbackInProvisioning(ESResult event)
+{
+ ESResult res = ES_OK;
+
+ if (event == ES_RECVTRIGGEROFPROVRES)
+ {
+ targetSsid = (char *) malloc(MAXSSIDLEN);
+ targetPass = (char *) malloc(MAXNETCREDLEN);
+
+ if (TerminateEasySetup() != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Terminating stack failed");
+ return;
+ }
+
+ GetTargetNetworkInfoFromProvResource(targetSsid, targetPass);
+
+ OC_LOG(INFO, TAG, targetSsid);
+ OC_LOG(INFO, TAG, targetPass);
+ OC_LOG(INFO, TAG, "Device Provisioned");
+
+ // cannot connect to target network, as currently arduino supports only one transport at a time
+ //res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
+
+ if (g_cbForProvisioning != NULL)
+ {
+ g_cbForProvisioning(res);
+ }
+ }
+}
+
+void EventCallbackAfterProvisioning(ESResult event)
+{
+ if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
+ {
+ if (g_cbForProvisioning != NULL)
+ {
+ g_cbForProvisioning(event);
+ }
+ }
+}
+
+ESResult InitEasySetup(NetworkType networkType, EventCallback cb)
+{
+
+ // Initialize the OC Stack in Server mode
+ //if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
+ if (OCInit1(OC_SERVER, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "OCStack init error");
+ return ES_ERROR;
+ }
+ else
+ {
+ OC_LOG(DEBUG, TAG, "OCStack init success");
+ return ES_OK;
+ }
+}
+
+ESResult TerminateEasySetup()
+{
+ if (OCStop() != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "OCStack stop failed");
+ return ES_ERROR;
+ }
+ else
+ {
+ OC_LOG(ERROR, TAG, "OCStack stop success");
+ return ES_OK;
+ }
+}
+
+ESResult InitProvisioning(EventCallback cb)
+{
+ if (cb == NULL)
+ {
+ return ES_ERROR;
+ }
+ else
+ {
+ g_cbForProvisioning = cb;
+ }
+
+ if (CreateProvisioningResource() != OC_STACK_OK)
+ {
+ return ES_ERROR;
+ }
+
+ RegisterResourceEventCallBack( EventCallbackInProvisioning);
+
+ return ES_RESOURCECREATED;
+}
+
NetResource g_net;
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *ehRequest,
- void *callback);
+ OCEntityHandlerRequest *ehRequest, void *callback);
const char *getResult(OCStackResult result);
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
- OCRepPayload** payload);
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
- OCRepPayload** payload);
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
- OCRepPayload** payload);
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
int g_flag = 0;
sprintf(g_prov.cd, "Unknown");
OCStackResult res = OCCreateResource(&g_prov.handle, "oic.prov", OC_RSRVD_INTERFACE_DEFAULT,
- OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+ OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb, NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res));
return res;
}
-
+#ifdef ESWIFI
OCStackResult CreateNetworkResource()
{
NetworkInfo netInfo;
return res;
}
-
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
- OCRepPayload **payload)
+#endif
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
- if(!ehRequest)
+ if (!ehRequest)
{
OC_LOG(ERROR, TAG, "Request is Null");
return ehResult;
}
- if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+ if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
OC_LOG(ERROR, TAG, "Incoming payload not a representation");
return ehResult;
}
OCRepPayload *getResp = constructResponse(ehRequest);
- if(!getResp)
+ if (!getResp)
{
OC_LOG(ERROR, TAG, "constructResponse failed");
return OC_EH_ERROR;
return ehResult;
}
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
- OCRepPayload** payload)
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
{
- OCEntityHandlerResult ehResult=OC_EH_ERROR;
- if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+ if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
OC_LOG(ERROR, TAG, "Incoming payload not a representation");
return ehResult;
}
- OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
- if(!input)
+ OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+ if (!input)
{
OC_LOG(ERROR, TAG, "Failed to parse");
return ehResult;
}
char* tnn;
- if(OCRepPayloadGetPropString(input,OC_RSRVD_ES_TNN, &tnn))
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
{
sprintf(g_prov.tnn, "%s", tnn);
}
char* cd;
- if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
{
sprintf(g_prov.cd, "%s", cd);
}
g_flag = 1;
OCRepPayload *getResp = constructResponse(ehRequest);
- if(!getResp)
+ if (!getResp)
{
OC_LOG(ERROR, TAG, "constructResponse failed");
return OC_EH_ERROR;
*payload = getResp;
ehResult = OC_EH_OK;
-
-
return ehResult;
}
-
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
- OCRepPayload** payload)
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
- if(!ehRequest)
+ if (!ehRequest)
{
OC_LOG(ERROR, TAG, "Request is Null");
return ehResult;
}
- if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+ if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
OC_LOG(ERROR, TAG, "Incoming payload not a representation");
return ehResult;
}
- OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
- if(!input)
+ OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+ if (!input)
{
OC_LOG(ERROR, TAG, "Failed to parse");
return ehResult;
}
char* tr;
- if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr))
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr))
{
// Triggering
OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
{
OCRepPayload* payload = OCRepPayloadCreate();
- if(!payload)
+ if (!payload)
{
OC_LOG(ERROR, TAG, "Failed to allocate Payload");
return NULL;
if (ehRequest->resource == g_prov.handle)
{
- OCRepPayloadSetUri(payload,OC_RSRVD_ES_URI_PROV);
- OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS,g_prov.ps);
+ OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, g_prov.ps);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, g_prov.tnt);
- OCRepPayloadSetPropString(payload,OC_RSRVD_ES_TNN, g_prov.tnn);
- OCRepPayloadSetPropString(payload,OC_RSRVD_ES_CD, g_prov.cd);
+ OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, g_prov.tnn);
+ OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, g_prov.cd);
}
else if (ehRequest->requestHandle == g_net.handle)
{
// This is the entity handler for the registered resource.
// This is invoked by OCStack whenever it recevies a request for this resource.
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest* entityHandlerRequest,void *callback)
+ OCEntityHandlerRequest* entityHandlerRequest, void *callback)
{
- (void)callback;
+ (void) callback;
OCEntityHandlerResult ehRet = OC_EH_OK;
OCEntityHandlerResponse response =
{ 0 };
response.resourceHandle = entityHandlerRequest->resource;
response.ehResult = ehRet;
//response uses OCPaylod while all get,put methodes use OCRepPayload
- response.payload = (OCPayload*)(payload);
+ response.payload = (OCPayload*) (payload);
response.numSendVendorSpecificHeaderOptions = 0;
memset(response.sendVendorSpecificHeaderOptions, 0,
sizeof response.sendVendorSpecificHeaderOptions);
{
switch (result)
{
- case OC_STACK_OK:
- return "OC_STACK_OK";
- case OC_STACK_INVALID_URI:
- return "OC_STACK_INVALID_URI";
- case OC_STACK_INVALID_QUERY:
- return "OC_STACK_INVALID_QUERY";
- case OC_STACK_INVALID_IP:
- return "OC_STACK_INVALID_IP";
- case OC_STACK_INVALID_PORT:
- return "OC_STACK_INVALID_PORT";
- case OC_STACK_INVALID_CALLBACK:
- return "OC_STACK_INVALID_CALLBACK";
- case OC_STACK_INVALID_METHOD:
- return "OC_STACK_INVALID_METHOD";
- case OC_STACK_NO_MEMORY:
- return "OC_STACK_NO_MEMORY";
- case OC_STACK_COMM_ERROR:
- return "OC_STACK_COMM_ERROR";
- case OC_STACK_INVALID_PARAM:
- return "OC_STACK_INVALID_PARAM";
- case OC_STACK_NOTIMPL:
- return "OC_STACK_NOTIMPL";
- case OC_STACK_NO_RESOURCE:
- return "OC_STACK_NO_RESOURCE";
- case OC_STACK_RESOURCE_ERROR:
- return "OC_STACK_RESOURCE_ERROR";
- case OC_STACK_SLOW_RESOURCE:
- return "OC_STACK_SLOW_RESOURCE";
- case OC_STACK_NO_OBSERVERS:
- return "OC_STACK_NO_OBSERVERS";
- case OC_STACK_ERROR:
- return "OC_STACK_ERROR";
- default:
- return "UNKNOWN";
+ case OC_STACK_OK:
+ return "OC_STACK_OK";
+ case OC_STACK_INVALID_URI:
+ return "OC_STACK_INVALID_URI";
+ case OC_STACK_INVALID_QUERY:
+ return "OC_STACK_INVALID_QUERY";
+ case OC_STACK_INVALID_IP:
+ return "OC_STACK_INVALID_IP";
+ case OC_STACK_INVALID_PORT:
+ return "OC_STACK_INVALID_PORT";
+ case OC_STACK_INVALID_CALLBACK:
+ return "OC_STACK_INVALID_CALLBACK";
+ case OC_STACK_INVALID_METHOD:
+ return "OC_STACK_INVALID_METHOD";
+ case OC_STACK_NO_MEMORY:
+ return "OC_STACK_NO_MEMORY";
+ case OC_STACK_COMM_ERROR:
+ return "OC_STACK_COMM_ERROR";
+ case OC_STACK_INVALID_PARAM:
+ return "OC_STACK_INVALID_PARAM";
+ case OC_STACK_NOTIMPL:
+ return "OC_STACK_NOTIMPL";
+ case OC_STACK_NO_RESOURCE:
+ return "OC_STACK_NO_RESOURCE";
+ case OC_STACK_RESOURCE_ERROR:
+ return "OC_STACK_RESOURCE_ERROR";
+ case OC_STACK_SLOW_RESOURCE:
+ return "OC_STACK_SLOW_RESOURCE";
+ case OC_STACK_NO_OBSERVERS:
+ return "OC_STACK_NO_OBSERVERS";
+ case OC_STACK_ERROR:
+ return "OC_STACK_ERROR";
+ default:
+ return "UNKNOWN";
}
}
import android.content.Context;
import android.util.Log;
+import org.iotivity.base.OcConnectivityType;
import org.iotivity.service.easysetup.core.BleConnection;
-import org.iotivity.service.easysetup.core.OnBoardingConnection;
+import org.iotivity.service.easysetup.core.ConnectionInterface;
import org.iotivity.service.easysetup.core.EnrolleeDevice;
import org.iotivity.service.easysetup.core.EnrolleeState;
import org.iotivity.service.easysetup.core.OnBoardingConfig;
}
};
- protected EnrolleeDeviceBLEOnBoarding(Context context, OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
+ protected EnrolleeDeviceBLEOnBoarding(Context context, OnBoardingConfig onBoardingConfig,
+ ProvisioningConfig provConfig) {
super(onBoardingConfig, provConfig);
mContext = context;
bleManager = new BLEManager(mContext, (BLEOnBoardingConfig) onBoardingConfig);
}
@Override
- protected void startProvisioningProcess(OnBoardingConnection conn) {
+ protected void startProvisioningProcess(ConnectionInterface conn) {
Log.i("start provisioning BLE", mProvConfig.getConnType() + "");
- //if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi)
- {
- provisionEnrolleInstance = new ProvisionEnrollee(mContext);
- provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {
- @Override
- public void onFinishProvisioning(int statuscode) {
- mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;
- mProvisioningCallback.onFinished(EnrolleeDeviceBLEOnBoarding.this);
- }
- });
-
- BleConnection connection = (BleConnection) conn;
- WiFiProvConfig wifiProvConfig = (WiFiProvConfig) mProvConfig;
- if (mContext == null)
- Log.d("BLE context is null", "");
- else Log.d("BLE context is not null", "");
- easySetupManagerNativeInstance = EasySetupManager.getInstance();
-
-
- easySetupManagerNativeInstance.setApplicationContext(mContext);
- easySetupManagerNativeInstance.initEasySetup();
- Log.d("init", "successful");
- easySetupManagerNativeInstance.provisionEnrollee(connection.getMacaddress(), wifiProvConfig.getSsId(), wifiProvConfig.getPassword(), 0);
+ provisionEnrolleInstance = new ProvisionEnrollee(mContext);
+ provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {
+ @Override
+ public void onFinishProvisioning(int statuscode) {
+ mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE :
+ EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;
+ mProvisioningCallback.onFinished(EnrolleeDeviceBLEOnBoarding.this);
+ }
+ });
+
+ BleConnection connection = (BleConnection) conn;
+ WiFiProvConfig wifiProvConfig = (WiFiProvConfig) mProvConfig;
+ easySetupManagerNativeInstance = EasySetupManager.getInstance();
+ easySetupManagerNativeInstance.setApplicationContext(mContext);
+ easySetupManagerNativeInstance.initEasySetup();
+ Log.d("init", "successful");
+ OcConnectivityType ocConnectivityType = OcConnectivityType.CT_ADAPTER_GATT_BTLE;
+ easySetupManagerNativeInstance.provisionEnrollee(connection.getMacaddress(),
+ wifiProvConfig.getSsId(),
+ wifiProvConfig.getPassword(),
+ ocConnectivityType.getValue());
- }
}
}
\ No newline at end of file
#include "jni_easy_setup_jvm.h"\r
#include "easysetupmgr.h"\r
\r
-void JNIProvisioningStatusCallback(ProvisioningInfo *provInfo) {\r
+void JNIProvisioningStatusCallback(ProvisioningInfo *provInfo)\r
+{\r
JNIEnv *env = EasySetupJVM::getEnv();\r
- if (env == NULL) {\r
+ if (env == NULL)\r
+ {\r
LOGE("JNIProvisioningStatusCallback : Getting JNIEnv failed");\r
return;\r
}\r
\r
// Get EasySetupHandler class reference\r
- jclass easysetupCallbacks = GetJClass(\r
- EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
- if (NULL == easysetupCallbacks) {\r
- LOGE(\r
- "JNIProvisioningStatusCallback : GetJClass easysetupCallbacks failed");\r
+ jclass easysetupCallbacks = GetJClass(EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
+ if (NULL == easysetupCallbacks)\r
+ {\r
+ LOGE("JNIProvisioningStatusCallback : GetJClass easysetupCallbacks failed");\r
EasySetupJVM::releaseEnv();\r
return;\r
}\r
\r
// Get the easysetupCallback class instance\r
- jobject jobjectCallback = GetJObjectInstance(\r
- EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
- if (NULL == jobjectCallback) {\r
- LOGE("getInstance( %s) failed!",\r
- EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
+ jobject jobjectCallback = GetJObjectInstance(EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
+ if (NULL == jobjectCallback)\r
+ {\r
+ LOGE("getInstance( %s) failed!", EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);\r
EasySetupJVM::releaseEnv();\r
return;\r
}\r
\r
// Get onResourceCallback method reference\r
- jmethodID method_id = env->GetMethodID(easysetupCallbacks,\r
- "ProvisioningStatusCallBack",\r
+ jmethodID method_id = env->GetMethodID(easysetupCallbacks, "ProvisioningStatusCallBack",\r
METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK);\r
- if (NULL == method_id) {\r
- LOGE(\r
- "JNIProvisioningStatusCallback: onResourceCallback : GetMethodID failed");\r
+ if (NULL == method_id)\r
+ {\r
+ LOGE("JNIProvisioningStatusCallback: onResourceCallback : GetMethodID failed");\r
EasySetupJVM::releaseEnv();\r
return;\r
}\r
\r
- if ((env)->ExceptionCheck()) {\r
+ if ((env)->ExceptionCheck())\r
+ {\r
LOGE("JNIProvisioningStatusCallback : ExceptionCheck failed");\r
EasySetupJVM::releaseEnv();\r
return;\r
}\r
\r
- if (NULL == method_id) {\r
+ if (NULL == method_id)\r
+ {\r
LOGI("JNI method_id is NULL");\r
- } else {\r
+ }\r
+ else\r
+ {\r
LOGI("JNI method_id is VALID");\r
\r
jint result;\r
- if (provInfo->provStatus == DEVICE_PROVISIONED) {\r
+ if (provInfo->provStatus == DEVICE_PROVISIONED)\r
+ {\r
result = 0;\r
- } else {\r
+ }\r
+ else\r
+ {\r
result = -1;\r
}\r
\r
TerminateEasySetupManager();\r
}\r
\r
-\r
JNIEXPORT void JNICALL JNIProvisionEnrollee(JNIEnv *env, jobject thisObj,\r
- jstring jIPAddress,\r
- jstring jNetSSID,\r
- jstring jNetPWD,\r
- jint jConnectivityType)\r
+ jstring jIPAddress,\r
+ jstring jNetSSID,\r
+ jstring jNetPWD,\r
+ jint jConnectivityType)\r
{\r
LOGI("JNI JNIProvisionEnrollee: Enter");\r
\r
LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD);\r
\r
OCConnectivityType connecitivityType;\r
- EnrolleeNWProvInfo_t netInfo = {0};\r
+ EnrolleeNWProvInfo_t netInfo =\r
+ { 0};\r
\r
strncpy(netInfo.netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE);\r
strncpy(netInfo.netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE);\r
strncpy(netInfo.netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE);\r
netInfo.connType = (OCConnectivityType)jConnectivityType;\r
+\r
+ if(netInfo.connType==CT_ADAPTER_GATT_BTLE)\r
+ {\r
+ strncpy(netInfo.netAddressInfo.LE.leMacAddress,ipAddress,NET_MACADDR_SIZE);\r
+ LOGI("MAC set=%s",netInfo.netAddressInfo.LE.leMacAddress);\r
+\r
+ }\r
netInfo.isSecured = true;\r
\r
ProvisionEnrollee(&netInfo);\r
}\r
\r
JNIEXPORT void JNICALL JNIStopEnrolleeProvisioning(JNIEnv *env, jobject thisObj,\r
- jint jConnectivityType)\r
+ jint jConnectivityType)\r
{\r
LOGI("JNI Stop Easy Setup: Entering");\r
\r
return;\r
}\r
\r
-\r
devaddress->adapter = OC_ADAPTER_GATT_BTLE;
if (strcmp(netProvInfo->netAddressInfo.WIFI.ipAddress, clientResponse->devAddr.addr))
- OIC_LOG(INFO, TAG, "equal");
+ OIC_LOG_V(INFO, TAG, "unequal %s %s", netProvInfo->netAddressInfo.WIFI.ipAddress,
+ clientResponse->devAddr.addr);
else
OIC_LOG_V(INFO, TAG, "unequal %s %s", netProvInfo->netAddressInfo.WIFI.ipAddress,
clientResponse->devAddr.addr);
netProvInfo->netAddressInfo.WIFI.pwd);
OIC_LOG_V(DEBUG, TAG, "Network Provisioning Info. MAC ADDRESS = %s",
- netProvInfo->netAddressInfo.WIFI.ipAddress);
+ netInfo->netAddressInfo.LE.leMacAddress);
return true;