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 ******************************************************************/
24 * This file contains common utility function for CA transport adaptors.
27 #ifndef _CA_ADAPTER_UTILS_H_
28 #define _CA_ADAPTER_UTILS_H_
40 * @def VERIFY_NON_NULL
41 * @brief Macro to verify the validity of input argument
43 #define VERIFY_NON_NULL(arg, log_tag, log_message) \
45 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
46 return CA_STATUS_INVALID_PARAM; \
50 * @def VERIFY_NON_NULL_RET
51 * @brief Macro to verify the validity of input argument
53 #define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \
55 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
60 * @def VERIFY_NON_NULL_VOID
61 * @brief Macro to verify the validity of input argument
63 #define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
65 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
70 * @def IPV4_ADDR_ONE_OCTECT_LEN
71 * @brief Macro to allocate memory for ipv4 address in the form of uint8_t.
73 #define IPV4_ADDR_ONE_OCTECT_LEN 4
76 * @brief To log the PDU data
78 void CALogPDUData(coap_pdu_t *pdu);
81 * @fn CAAdapterCreateLocalEndpoint
82 * @brief Create CALocalConnectivity_t instance.
84 CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CAConnectivityType_t type,
88 * @fn CAAdapterCopyLocalEndpoint
89 * @brief Create CALocalConnectivity_t duplicate instance.
91 CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity);
94 * @fn CAAdapterFreeLocalEndpoint
95 * @brief Deallocate CALocalConnectivity_t instance.
97 void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndPoint);
100 * @fn CAAdapterCreateRemoteEndpoint
101 * @brief Allocate CARemoteEndpoint_t instance.
103 CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CAConnectivityType_t type,
104 const char *address, const char *resourceUri);
107 * @fn CAAdapterCopyRemoteEndpoint
108 * @brief Create CARemoteEndpoint_t duplicate instance.
110 CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(
111 const CARemoteEndpoint_t *remoteEndpoint);
114 * @fn CAAdapterFreeRemoteEndpoint
115 * @brief Deallocate CARemoteEndpoint_t instance.
117 void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint);
120 * @fn CAParseIPv4AddressInternal
121 * @brief To parse the IP address and port from "ipaddress:port"
122 * @param ipAddrStr [IN] IP address to be parsed
123 * @param ipAddr [OUT] Parsed IP address
124 * @param ipAddr [IN] Buffer length for parsed IP address
125 * @param port [OUT] Parsed Port number
126 * @return #CA_STATUS_OK or Appropriate error code
128 CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr,
129 size_t ipAddrLen, uint16_t *port);
132 * @fn CAAdapterIsSameSubnet
133 * @brief Check if two ip address belong to same subnet
135 bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2,
136 const char *netMask);
140 #endif // _CA_ADAPTER_UTILS_H_