Imported Upstream version 0.9.1
[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_singlethread.h"
25
26 #include <Arduino.h>
27 #include <SPI.h>
28 #include <boards.h>
29 #include <RBL_nRF8001.h>
30
31 #include "caleadapter_singlethread.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 CALEInitializeNetworkMonitor()
54 {
55     OIC_LOG(DEBUG, TAG, "IN");
56     OIC_LOG(DEBUG, TAG, "OUT");
57     return CA_STATUS_OK;
58 }
59
60 void CALETerminateNetworkMonitor()
61 {
62     OIC_LOG(DEBUG, TAG, "IN");
63     OIC_LOG(DEBUG, TAG, "OUT");
64 }
65
66 CAResult_t CAGetLEAdapterState()
67 {
68     OIC_LOG(DEBUG, TAG, "IN");
69     OIC_LOG(DEBUG, TAG, "OUT");
70     return CA_STATUS_OK;
71 }
72
73 CAResult_t CAGetLEAddress(char **leAddress)
74 {
75     OIC_LOG(DEBUG, TAG, "IN");
76     VERIFY_NON_NULL(leAddress, TAG, "leAddress");
77
78     g_leAddress = ble_getAddress();
79     /**
80      *   Below Allocated Memory will be freed by caller API
81      */
82     *leAddress = (char*)OICMalloc(CA_MACADDR_SIZE);
83     if (NULL == *leAddress)
84     {
85         OIC_LOG(ERROR, TAG, "malloc fail");
86         return CA_MEMORY_ALLOC_FAILED;
87     }
88     memcpy(*leAddress, g_leAddress, CA_MACADDR_SIZE);
89     OIC_LOG(DEBUG, TAG, "OUT");
90     return CA_STATUS_OK;
91 }
92
93 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback)
94 {
95     OIC_LOG(DEBUG, TAG, "IN");
96
97     g_caLEDeviceStateChangedCallback = callback;
98
99     OIC_LOG(DEBUG, TAG, "OUT");
100     return CA_STATUS_OK;
101 }
102
103 CAResult_t CAUnSetLEAdapterStateChangedCb()
104 {
105     OIC_LOG(DEBUG, TAG, "IN");
106
107     g_caLEDeviceStateChangedCallback = NULL;
108
109     OIC_LOG(DEBUG, TAG, "OUT");
110     return CA_STATUS_OK;
111 }
112
113