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 ******************************************************************/
21 * @file caipnwmonitor.cpp
22 * @brief This file is to keep design in sync with other platforms. Right now there is no
23 * 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 /// Retrieves the IP address assigned to Arduino Ethernet shield
49 void CAArduinoGetInterfaceAddress(uint32_t *address)
51 OIC_LOG(DEBUG, TAG, "IN");
52 VERIFY_NON_NULL_VOID(address, TAG, "address");
54 //TODO : Fix this for scenarios when this API is invoked when device is not connected
56 W5100.getIPAddress(rawIPAddr);
57 *address = (uint32_t) rawIPAddr;
59 OIC_LOG_V(DEBUG, TAG, "address:%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1],
60 rawIPAddr[2], rawIPAddr[3]);
61 OIC_LOG(DEBUG, TAG, "OUT");
65 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
69 u_arraylist_t *iflist = u_arraylist_create();
72 OIC_LOG(ERROR, TAG, "Failed to create iflist");
76 CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(CAInterface_t));
79 OIC_LOG(ERROR, TAG, "Malloc failed");
83 // Since Arduino currently only supports one interface, the next 4 lines are sufficient.
84 OICStrcpy(ifitem->name, INTERFACE_NAME_MAX, "ETH");
86 ifitem->family = AF_INET;
88 CAArduinoGetInterfaceAddress(&ifitem->ipv4addr);
90 result = u_arraylist_add(iflist, ifitem);
91 if (CA_STATUS_OK != result)
93 OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
97 OIC_LOG_V(ERROR, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family);
102 u_arraylist_destroy(iflist);