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 * @file caadapterutils.h
23 * @brief This file contains common utility function for CA transport adaptors.
26 #ifndef _CA_ADAPTER_UTILS_H_
27 #define _CA_ADAPTER_UTILS_H_
39 * @def VERIFY_NON_NULL
40 * @brief Macro to verify the validity of input argument
42 #define VERIFY_NON_NULL(arg, log_tag, log_message) \
44 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
45 return CA_STATUS_INVALID_PARAM; \
49 * @def VERIFY_NON_NULL_RET
50 * @brief Macro to verify the validity of input argument
52 #define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \
54 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
59 * @def VERIFY_NON_NULL_VOID
60 * @brief Macro to verify the validity of input argument
62 #define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
64 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
69 * @def IPV4_ADDR_ONE_OCTECT_LEN
70 * @brief Macro to allocate memory for ipv4 address in the form of uint8_t.
72 #define IPV4_ADDR_ONE_OCTECT_LEN 4
75 * @brief To log the PDU data
77 void CALogPDUData(coap_pdu_t *pdu);
80 * @fn CAAdapterCreateLocalEndpoint
81 * @brief Create CALocalConnectivity_t instance.
83 CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CAConnectivityType_t type,
87 * @fn CAAdapterCopyLocalEndpoint
88 * @brief Create CALocalConnectivity_t duplicate instance.
90 CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity);
93 * @fn CAAdapterFreeLocalEndpoint
94 * @brief Deallocate CALocalConnectivity_t instance.
96 void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndPoint);
99 * @fn CAAdapterCreateRemoteEndpoint
100 * @brief Allocate CARemoteEndpoint_t instance.
102 CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CAConnectivityType_t type,
103 const char *address, const char *resourceUri);
106 * @fn CAAdapterCopyRemoteEndpoint
107 * @brief Create CARemoteEndpoint_t duplicate instance.
109 CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(
110 const CARemoteEndpoint_t *remoteEndpoint);
113 * @fn CAAdapterFreeRemoteEndpoint
114 * @brief Deallocate CARemoteEndpoint_t instance.
116 void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint);
119 * @fn CAParseIPv4AddressInternal
120 * @brief To parse the IP address and port from "ipaddress:port"
121 * @param ipAddrStr [IN] IP address to be parsed
122 * @param ipAddr [OUT] Parsed IP address
123 * @param ipAddr [IN] Buffer length for parsed IP address
124 * @param port [OUT] Parsed Port number
125 * @return #CA_STATUS_OK or Appropriate error code
127 CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr,
128 size_t ipAddrLen, uint16_t *port);
131 * @fn CAAdapterIsSameSubnet
132 * @brief Check if two ip address belong to same subnet
134 bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2,
135 const char *netMask);
139 #endif // _CA_ADAPTER_UTILS_H_