Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / arduino / cablenwmonitor.cpp
1 /******************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20
21 //logger.h included first to avoid conflict with RBL library PROGMEM attribute
22 #include "logger.h"
23
24 #include "caleinterface.h"
25
26 #include <Arduino.h>
27 #include <SPI.h>
28 #include <boards.h>
29 #include <RBL_nRF8001.h>
30
31 #include "caleadapter.h"
32 #include "caadapterutils.h"
33 #include "oic_malloc.h"
34
35 /**
36  * @def TAG
37  * @brief Logging tag for module name
38  */
39 #define TAG "LENW"
40
41 /**
42  * @var g_caLEDeviceStateChangedCallback
43  * @brief Maintains the callback to be notified on device state changed.
44  */
45 static CALEDeviceStateChangedCallback g_caLEDeviceStateChangedCallback = NULL;
46
47 /**
48  * @var g_leAddress
49  * @brief Maintains the local BLE Shield Address
50  */
51 static unsigned char *g_leAddress = NULL;
52
53 CAResult_t CAInitializeLENetworkMonitor()
54 {
55     OIC_LOG(DEBUG, TAG, "IN");
56     OIC_LOG(DEBUG, TAG, "OUT");
57     return CA_STATUS_OK;
58 }
59
60 void CATerminateLENetworkMonitor()
61 {
62     OIC_LOG(DEBUG, TAG, "IN");
63     OIC_LOG(DEBUG, TAG, "OUT");
64 }
65
66 CAResult_t CAInitializeLEAdapter()
67 {
68     OIC_LOG(DEBUG, TAG, "IN");
69     OIC_LOG(DEBUG, TAG, "OUT");
70     return CA_STATUS_OK;
71 }
72
73 CAResult_t CAGetLEAdapterState()
74 {
75     OIC_LOG(DEBUG, TAG, "IN");
76     OIC_LOG(DEBUG, TAG, "OUT");
77     return CA_STATUS_OK;
78 }
79
80 CAResult_t CAGetLEAddress(char **leAddress)
81 {
82     OIC_LOG(DEBUG, TAG, "IN");
83     VERIFY_NON_NULL(leAddress, TAG, "leAddress");
84
85     g_leAddress = ble_getAddress();
86     /**
87      *   Below Allocated Memory will be freed by caller API
88      */
89     *leAddress = (char*)OICMalloc(CA_MACADDR_SIZE);
90     if (NULL == *leAddress)
91     {
92         OIC_LOG(ERROR, TAG, "malloc fail");
93         return CA_MEMORY_ALLOC_FAILED;
94     }
95     memcpy(*leAddress, g_leAddress, CA_MACADDR_SIZE);
96     OIC_LOG(DEBUG, TAG, "OUT");
97     return CA_STATUS_OK;
98 }
99
100 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback)
101 {
102     OIC_LOG(DEBUG, TAG, "IN");
103
104     g_caLEDeviceStateChangedCallback = callback;
105
106     OIC_LOG(DEBUG, TAG, "OUT");
107     return CA_STATUS_OK;
108 }
109
110 CAResult_t CAUnSetLEAdapterStateChangedCb()
111 {
112     OIC_LOG(DEBUG, TAG, "IN");
113
114     g_caLEDeviceStateChangedCallback = NULL;
115
116     OIC_LOG(DEBUG, TAG, "OUT");
117     return CA_STATUS_OK;
118 }
119
120