2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __ASP_SESSION_H__
18 #define __ASP_SESSION_H__
26 /*****************************************************************************
28 *****************************************************************************/
31 ASP_SESSION_CONNECT_STATUS_NETWORK_ROLE_REJECTED,
32 ASP_SESSION_CONNECT_STATUS_NO_MORE_CONNECTION,
33 ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_SENT,
34 ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_RECEIVED,
35 ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_DEFFERED,
36 ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_ACCEPTED,
37 ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_FAILED,
38 ASP_SESSION_CONNECT_STATUS_GROUP_FORMATION_STARTED,
39 ASP_SESSION_CONNECT_STATUS_GROUP_FORMATION_COMPLETED,
40 ASP_SESSION_CONNECT_STATUS_GROUP_FORMATION_FAILED,
41 } asp_session_connect_status_e;
44 ASP_SESSION_STATE_ERROR,
45 ASP_SESSION_STATE_CLOSED,
46 ASP_SESSION_STATE_INITIATED,
47 ASP_SESSION_STATE_REQUESTED,
48 ASP_SESSION_STATE_OPEN
49 } asp_session_status_e;
52 ASP_SESSION_CLOSED_STATE_NONE,
53 ASP_SESSION_CLOSED_STATE_DISASSOCIATED,
54 ASP_SESSION_CLOSED_STATE_LOCAL_CLOSE,
55 ASP_SESSION_CLOSED_STATE_REMOTE_CLOSE,
56 ASP_SESSION_CLOSED_STATE_SYSTEM_FAILURE,
57 ASP_SESSION_CLOSED_STATE_NO_RESPONSE_FROM_REMOTE
58 } asp_session_closed_state_e;
61 ASP_SESSION_PORT_STATUS_LOCAL_PORT_ALLOWED,
62 ASP_SESSION_PORT_STATUS_LOCAL_PORT_BLOCKED,
63 ASP_SESSION_PORT_STATUS_FAILURE,
64 ASP_SESSION_PORT_STATUS_REMOTE_PORT_ALLOWED
65 } asp_session_port_status_e;
68 ASP_SESSION_REMOVE_SESSION_REASON_UNKNOWN = 0x00,
69 ASP_SESSION_REMOVE_SESSION_REASON_REJECTED_BY_USER = 0x01,
70 ASP_SESSION_REMOVE_SESSION_REASON_ADVERTISED_SERVICE_NOT_AVAILABLE = 0x02,
71 ASP_SESSION_REMOVE_SESSION_REASON_SYSTEM_FAILURE = 0x03
72 } asp_remove_session_reason_e;
74 typedef void (*asp_session_session_request_cb) (gint32 error_code,
75 guint8 *session_mac, guint32 session_id, guint32 adv_id,
76 gchar *device_name, size_t name_length, guint8 *session_info,
77 size_t info_length, gboolean get_pin, guint32 pin, gpointer user_data);
78 /*if pin is zero, it does not need to be displayed. */
80 typedef void (*asp_session_session_config_request_cb) (gint32 error_code,
81 guint8 *session_mac, guint32 session_id, gboolean get_pin, guint32 pin,
84 typedef void (*asp_session_connect_status_cb) (gint32 error_code,
85 const guint8 *session_mac, guint32 session_id,
86 asp_session_connect_status_e status, guint8 *deferred_resp,
87 size_t resp_length, gpointer user_data);
89 typedef void (*asp_session_session_status_cb) (gint32 error_code,
90 const guint8 *session_mac, guint32 session_id,
91 asp_session_status_e state, asp_session_closed_state_e status,
92 const gchar *requested_info, gpointer user_data);
94 typedef void (*asp_session_port_status_cb) (gint32 error_code,
95 const guint8 *session_mac, guint32 session_id, const gchar *ip,
96 guint16 port, guint8 protocol, asp_session_port_status_e status,
99 /*****************************************************************************
100 * Functions Declaration
101 *****************************************************************************/
104 * @brief initialize asp-session
107 * @paragraph <Example>
108 * asp-seesion will be initialized.
113 gboolean asp_session_initialize(void);
116 * @brief deinitialize asp-session
119 * @paragraph <Example>
120 * asp-seesion will be deinitialized.
125 gboolean asp_session_deinitialize(void);
128 * @brief ASP session method - ConnectSession over P2P
129 * @param [in] service_mac p2p mac address of advertizer
130 * @param [in] adv_id advertisement ID assigned by the ASP when the Advertise Service method is called
131 * @param [in] session_info service-specific data payload(up to 144 bytes)
132 * @param [in] info_length length of 'session_info' parameter
133 * @param [in] network_role
134 * @param [in] network_config
135 * @param [out] session_mac mac address of the device that is calling this method
136 * @param [out] session_id ID of newly created session.
139 * @paragraph <Example>
140 * asp-seesion will be deinitialized.
145 gboolean asp_session_connect_session_over_p2p(const guint8 *service_mac,
146 guint32 adv_id, const guint8 *session_info, size_t info_length,
147 guint8 network_role, guint8 network_config, guint8 *session_mac,
148 guint32 *session_id);
151 * @brief ASP session method - ConnectSession over infra
152 * @param [in] peer_ip string type of peer's ip address like "111.222.333.444"
153 * @param [in] adv_id advertisement ID assigned by the ASP when the AdvertiseService method is called
154 * @param [in] session_info service-specific data payload(up to 144 bytes)
155 * @param [in] length length of 'session_info' parameter
156 * @param [out] session_mac mac address of the device that is calling this method
157 * @param [out] session_id ID of newly created session.
160 * @paragraph <Example>
161 * asp-seesion will be deinitialized.
166 gboolean asp_session_connect_session_over_infra(const gchar *peer_ip,
167 guint32 adv_id, guint8 *session_info, size_t length,
168 guint8 *session_mac, guint32 *session_id);
171 * @brief ASP session method - ConfirmSession
172 * @param [in] session_mac mac address of the device that assigned the value of session_id
173 * @param [in] session_id ASP session ID assigned by the remote ASP
174 * @param [in] confirmed TRUE or FALSE for session confirm
175 * @param [in] pin required by SessionConfigRequest event
178 * @paragraph <Example>
179 * asp-session will process 2 cases by confirmed parameter.
180 * in case of confrimed == TRUE => wait set_session_ready() from asp-manager
181 * in case of confirmed == FALSE > send REJECTED_SESSION coordination protocol messasge to peer
186 gboolean asp_session_confirm_session(const guint8 *session_mac,
187 guint32 session_id, gboolean confirmed, guint32 pin);
190 * @brief ASP session method - SetSessionReady
191 * @param [in] session_mac mac address of the device that assigned the value of session_id
192 * @param [in] session_id ASP session ID assigned by the remote ASP
195 * @paragraph <Example>
196 * asp-session will send ADDED_SESSION coordination protocol message to peer
201 gboolean asp_session_set_session_ready(const guint8 *session_mac, guint32 session_id);
204 * @brief ASP session method - CloseSssion
205 * @param [in] session_mac mac address of the device that assigned the value of session_id
206 * @param [in] session_id ASP session ID assigned by the remote ASP
207 * @param [in] reason reason of remove session
210 * @paragraph <Example>
211 * asp-session will send REMOVE_SESSION coordination protocol message to peer
216 gboolean asp_session_close_session(guint8 *session_mac, guint32 session_id,
217 asp_remove_session_reason_e reason);
220 * @brief ASP session method - BoundPort
221 * @param [in] session_mac mac address of the device that assigned the value of session_id
222 * @param [in] session_id ASP session ID assigned by the remote ASP
223 * @param [in] ip IP address on which the port is being used
224 * @param [in] port port number to be allowed
225 * @param [in] protocol The IANA protocol number
228 * @paragraph <Example>
229 * asp-seesion will send ALLOWED_PORT coordination protocol message to peer
234 gboolean asp_session_bound_port(guint8 *session_mac, guint32 session_id,
235 const gchar *ip, guint16 port, guint8 protocol);
238 * @brief method to set a session to a deferred session
239 * @param [in] session_mac mac address of the device that assigned the value of session_id
240 * @param [in] session_id ASP session ID assigned by the remote ASP
241 * @param [in] deferred_response reason of deferred session
242 * @param [in] length length of 'deferred_response' parameter
245 * @paragraph <Example>
246 * asp-seesion will send DEFERRED_SESSION coordination protocol message to peer
251 gboolean asp_session_defer_session(guint8 *session_mac, guint32 session_id,
252 guint8 *deferred_response, size_t length);
255 * @brief method to get an advertisement MAC from a session
256 * @param [in] session_mac mac address of the device that assigned the value of session_id
257 * @param [in] session_id ASP session ID assigned by the remote ASP
258 * @param [out] adv_mac advertisement MAC
261 * @paragraph <Example>
265 * asp_session_get_advertisement_mac(session_mac, session_id, &adv_mac);
268 gboolean asp_session_get_advertisement_mac(const guint8 *session_mac,
269 guint32 session_id, guint8 **adv_mac);
272 * @brief method to get an advertisement ID from a session
273 * @param [in] session_mac mac address of the device that assigned the value of session_id
274 * @param [in] session_id ASP session ID assigned by the remote ASP
275 * @param [out] adv_id advertisement ID
278 * @paragraph <Example>
282 * asp_session_get_advertisement_id(session_mac, session_id, &adv_id);
285 gboolean asp_session_get_advertisement_id(const guint8 *session_mac,
286 guint32 session_id, guint32 *adv_id);
289 * @brief method to get a session state from a session
290 * @param [in] session_mac mac address of the device that assigned the value of session_id
291 * @param [in] session_id ASP session ID assigned by the remote ASP
292 * @param [out] state current state of session. one of [OPEN, INITIATED, REQUESTED, CLOSE]
295 * @paragraph <Example>
298 * asp_session_status_e state;
299 * asp_session_get_state(session_mac, sessoin_id, &state);
302 gboolean asp_session_get_state(guint8 *session_mac, guint32 session_id,
303 asp_session_status_e *state);
306 * @brief method to get ip & port of the peer.
307 * @param [in] session_mac mac address of the device that assigned the value of session_id
308 * @param [in] session_id ASP session ID assigned by the remote ASP
309 * @param [out] peer_ip ip string
310 * @param [out] port port num
313 * @paragraph <Example>
316 * gchar ip[16]; // example of IPV4
318 * asp_session_get_peer_endpoint(session_mac, session_id, ip, &port);
321 gboolean asp_session_get_peer_endpoint(guint8 *session_mac, guint32 session_id,
322 gchar *peer_ip, guint16 *port);
325 * @brief method to register a callback for ASP SessionReqeust event
326 * @param [in] cb a callback for ASP SessionRequest event
327 * @param [in] user_data callback user data
330 * @paragraph <Example>
331 * the registered callback will be triggered when session reqeust callback need to be called
334 * void my_cb(gint32 error_code, guint8* session_mac, guint32 session_id, guint32 adv_id, guint8* session_info, size_t length, gpointer user_data)
337 * asp_session_set_session_request_cb(some_cb,
340 gboolean asp_session_set_session_request_cb(asp_session_session_request_cb cb, gpointer user_data);
343 * @brief method to register a callback for ASP SessionConfigRequest event
344 * @param [in] cb a callback for ASP SessionConfigRequest event
345 * @param [in] user_data callback user data
348 * @paragraph <Example>
349 * the registered callback will be triggered when session request callback need to be called
352 * void my_cb (gint32 error_code, guint8* session_mac, guint32 session_id, gboolean get_pin, guint32 pin, gpointer user_data)
355 * asp_session_set_session_config_request_cb(some_cb, (gpointer) user_data);
358 gboolean asp_session_set_session_config_request_cb(asp_session_session_config_request_cb cb, gpointer user_data);
361 * @brief method to register a callback for ASP ConnectStatus event
362 * @param [in] cb a callback for ASP ConnectStatus event
363 * @param [in] user_data callback user data
366 * @paragraph <Example>
367 * the registered callback will be triggered when connect status callback need to be called
370 * void my_cb(gint32 error_code, const guint8* session_mac, guint32 session_id, asp_session_connect_status_e status, guint8* deferred_resp, size_t resp_length, gpointer user_data);
373 * asp_session_set_connect_status_cb(some_cb, (gpointer) user_data);
376 gboolean asp_session_set_connect_status_cb(asp_session_connect_status_cb cb, gpointer user_data);
379 * @brief method to register a callback for ASP SessionStatus event
380 * @param [in] cb a callback for ASP SessionStatus event
381 * @param [in] user_data callback user data
384 * @paragraph <Example>
385 * the registered callback will be triggered when connect status callback need to be called
388 * void my_cb(gint32 error_code, const guint8* session_mac, guint32 session_id, asp_session_status_e state, asp_session_closed_state_e status, const gchar* requested_info, gpointer user_data);
391 * asp_session_set_session_request_cb(some_cb, (gpointer) user_data);
394 gboolean asp_session_set_session_status_cb(asp_session_session_status_cb cb, gpointer user_data);
397 * @brief method to register a callback for ASP PortStatus event
398 * @param [in] cb a callback for ASP PortStatus event
399 * @param [in] user_data callback user data
402 * @paragraph <Example>
403 * the registered callback will be triggered when port status callback need to be called
406 * void my_cb(gint32 error_code, const guint8* session_mac, guint32 session_id, const gchar* peer_ip, guint16 port, guint8 protocol, asp_session_port_status_e status, gpointer user_data);
409 * asp_session_set_session_request_cb(my_cb, (gpointer) user_data);
412 gboolean asp_session_set_port_status_cb(asp_session_port_status_cb cb, gpointer user_data);
418 #endif /* __ASP_SESSION_H__ */