1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
22 * This file is to keep design in sync with other platforms. Right now
23 * there is no api for network monitoring in arduino.
26 #include "caipinterface.h"
32 #include <utility/server_drv.h>
33 #include <utility/wifi_drv.h>
34 #include <IPAddress.h>
38 #include "caipadapter.h"
39 #include "caadapterutils.h"
40 #include "oic_malloc.h"
41 #include "oic_string.h"
45 // Since the CA abstraction expects a value for "family", AF_INET will be
46 // defined & used (as-is defined in the linux socket headers).
49 CAResult_t CAIPStartNetworkMonitor()
54 CAResult_t CAIPStopNetworkMonitor()
59 /// Retrieves the IP address assigned to Arduino WiFi shield
60 void CAArduinoGetInterfaceAddress(uint32_t *address)
62 OIC_LOG(DEBUG, TAG, "IN");
63 if (WiFi.status() != WL_CONNECTED)
65 OIC_LOG(DEBUG, TAG, "No WIFI");
69 VERIFY_NON_NULL_VOID(address, TAG, "Invalid address");
71 IPAddress ip = WiFi.localIP();
72 *address = (uint32_t) ip;
74 OIC_LOG_V(DEBUG, TAG, "Wifi shield address is: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
75 OIC_LOG(DEBUG, TAG, "OUT");
79 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
83 u_arraylist_t *iflist = u_arraylist_create();
86 OIC_LOG(ERROR, TAG, "Failed to create iflist");
90 CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(CAInterface_t));
93 OIC_LOG(ERROR, TAG, "Malloc failed");
97 // Since Arduino currently only supports one interface, the next 4 lines are sufficient.
98 OICStrcpy(ifitem->name, INTERFACE_NAME_MAX, "WIFI");
100 ifitem->family = AF_INET;
102 CAArduinoGetInterfaceAddress(&ifitem->ipv4addr);
104 result = u_arraylist_add(iflist, ifitem);
107 OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
111 OIC_LOG_V(ERROR, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family);
116 u_arraylist_destroy(iflist);