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 <EthernetUdp.h>
33 #include <IPAddress.h>
37 #include "caipadapter.h"
38 #include "caadapterutils.h"
39 #include "oic_malloc.h"
40 #include "oic_string.h"
44 // Since the CA abstraction expects a value for "family", AF_INET will be
45 // defined & used (as-is defined in the linux socket headers).
48 CAResult_t CAIPInitializeNetworkMonitor()
53 CAResult_t CAIPTerminateNetworkMonitor()
58 /// Retrieves the IP address assigned to Arduino Ethernet shield
59 void CAArduinoGetInterfaceAddress(uint32_t *address)
61 OIC_LOG(DEBUG, TAG, "IN");
62 VERIFY_NON_NULL_VOID(address, TAG, "address");
64 //TODO : Fix this for scenarios when this API is invoked when device is not connected
66 W5100.getIPAddress(rawIPAddr);
67 *address = (uint32_t) rawIPAddr;
69 OIC_LOG_V(DEBUG, TAG, "address:%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1],
70 rawIPAddr[2], rawIPAddr[3]);
71 OIC_LOG(DEBUG, TAG, "OUT");
75 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
79 u_arraylist_t *iflist = u_arraylist_create();
82 OIC_LOG(ERROR, TAG, "Failed to create iflist");
86 CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(CAInterface_t));
89 OIC_LOG(ERROR, TAG, "Malloc failed");
93 // Since Arduino currently only supports one interface, the next 4 lines are sufficient.
94 OICStrcpy(ifitem->name, INTERFACE_NAME_MAX, "ETH");
96 ifitem->family = AF_INET;
98 CAArduinoGetInterfaceAddress(&ifitem->ipv4addr);
100 result = u_arraylist_add(iflist, ifitem);
103 OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
107 OIC_LOG_V(ERROR, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family);
112 u_arraylist_destroy(iflist);