caipinterface.h 5.63 KB
Newer Older
1
/******************************************************************
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************/
20 21

/**
22 23
 * @file caipinterface.h
 * @brief This file provides APIs IP client/server/network monitor modules
24 25
 */

26 27
#ifndef CA_IP_INTERFACE_H_
#define CA_IP_INTERFACE_H_
28 29 30 31

#include <stdbool.h>

#include "cacommon.h"
32
#include "cathreadpool.h"
33
#include "uarraylist.h"
34 35 36 37 38 39 40 41 42 43 44 45

#ifdef __cplusplus
extern "C"
{
#endif

/**
 * @enum CAAdapterServerType_t
 * @brief Enum for defining different server types.
 */
typedef enum
{
46 47 48
    CA_UNICAST_SERVER = 0,      /**< Unicast Server */
    CA_MULTICAST_SERVER,        /**< Multicast Server */
    CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
49 50 51
} CAAdapterServerType_t;

/**
52
 * @brief Callback to be notified on reception of any data from remote OIC devices.
53
 *
54
 * @param  endpoint     [IN] network endpoint description
55 56
 * @param  data         [IN] Data received from remote OIC device.
 * @param  dataLength   [IN] Length of data in bytes.
57
 *
58
 * @return NONE
59
 * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
60
 */
61 62 63
typedef void (*CAIPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
                                           const void *data,
                                           uint32_t dataLength);
64

jnashok's avatar
jnashok committed
65 66 67 68 69 70 71 72 73 74 75 76 77
/**
  * @brief Callback to notify error in the IP adapter
  *
  * @param  endpoint     [IN] [IN] network endpoint description
  * @param  data         [IN] Data sent/received
  * @param  dataLength   [IN] Length of data in bytes.
  * @param  result       [IN] result of request from R.I
  * @return NONE
  * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
 */
typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
                                        uint32_t dataLength, CAResult_t result);

78 79
/**
 * @brief  Callback to be notified when exception occures on multicast/unicast server.
80 81
 * @param  type  [IN] Type of server(#CAAdapterServerType_t)
 * @return NONE
82
 * @pre  Callback must be registered using CAIPSetExceptionCallback()
83
 */
84
typedef void (*CAIPExceptionCallback)(CAAdapterServerType_t type);
85 86

/**
John Light's avatar
John Light committed
87
 * @brief  Start IP server
88
 *
89
 * @param   threadPool  [IN] Thread pool for managing Unicast/Multicast server threads.
90
 *
91
 * @return  #CA_STATUS_OK or Appropriate error code
92 93 94 95
 * @retval  #CA_STATUS_OK  Successful
 * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
 * @retval  #CA_STATUS_FAILED Initialization failed
 */
John Light's avatar
John Light committed
96 97 98 99 100
#ifdef SINGLE_THREAD
CAResult_t CAIPStartServer();
#else
CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
#endif
101 102

/**
John Light's avatar
John Light committed
103
 * @brief  Stop IP server
104
 * @return NONE
105
 */
John Light's avatar
John Light committed
106
void CAIPStopServer();
107 108 109 110 111

/**
 * @brief  Set this callback for receiving data packets from peer devices.
 *
 * @param  callback   [IN] Callback to be notified on reception of unicast/multicast data packets.
112
 *
113
 * @return  NONE
114
 */
115
void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
116

117
/**
118 119 120
 * @brief  Set this callback for receiving exception notifications.
 *
 * @param  callback [IN] Callback to be notified on occurance of exception on running servers.
121
 *
122
 * @return  NONE
123
 */
124
void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
125

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
/**
 * @brief  Set socket description for sending unicast UDP data. Once the Unicast server is started,
 *         the same socket descriptor is used for sending the Unicast UDP data.
 *
 * @param  socketFD [IN]  Socket descriptor used for sending UDP data.
 * @return  NONE
 */
void CAIPSetUnicastSocket(int socketFD);

/**
 * @brief  Set the port number for sending unicast UDP data
 * @param  port [IN] Port number used for sending UDP data.
 * @return NONE
 */
void CAIPSetUnicastPort(uint16_t port);

142 143 144
/**
 * @brief  API to send unicast UDP data
 *
145
 * @param  endpoint         [IN] complete network address to send to
146 147 148
 * @param  data             [IN] Data to be send.
 * @param  dataLength       [IN] Length of data in bytes
 * @param  isMulticast      [IN] Whether data needs to be sent to multicast ip
149
 */
John Light's avatar
John Light committed
150 151 152 153
void CAIPSendData(CAEndpoint_t *endpoint,
                  const void *data,
                  uint32_t dataLength,
                  bool isMulticast);
154 155

/**
John Light's avatar
John Light committed
156
 * @brief  Get IP adapter connection state.
157
 *
John Light's avatar
John Light committed
158
 * @return  True if IP adapter is connected, otherwise false
159
 */
John Light's avatar
John Light committed
160
bool CAIPIsConnected();
161

162 163 164 165 166 167
/**
 * @brief  Pull the Received Data
 * @return NONE
 */
void CAIPPullData();

John Light's avatar
John Light committed
168 169 170
#define CA_COAP        5683
#define CA_SECURE_COAP 5684
#define INTERFACE_NAME_MAX 16
171

John Light's avatar
John Light committed
172 173 174 175 176 177 178 179
typedef struct
{
    char name[INTERFACE_NAME_MAX];
    uint32_t index;
    uint32_t flags;
    uint16_t family;
    uint32_t ipv4addr;        // used for IPv4 only
} CAInterface_t;
180 181

/**
John Light's avatar
John Light committed
182
 * @brief  Get a list of CAInterface_t items
183
 *
John Light's avatar
John Light committed
184
 * @return  List of CAInterface_t items
185
 */
John Light's avatar
John Light committed
186
u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
187

jnashok's avatar
jnashok committed
188 189 190 191 192 193 194 195
/**
 * @brief  Set callback for error handling
 *
 * @param  ipErrorCallback [IN] callback to notify error to the ipadapter
 * @return NONE
 */
void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback);

196 197 198 199
#ifdef __cplusplus
}
#endif

200
#endif /* CA_IP_INTERFACE_H_ */