Revise directory structure
[platform/core/connectivity/asp-manager.git] / src / asp-coordination-protocol.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __ASP_COORDINATION_PROTOCOL_H__
18 #define __ASP_COORDINATION_PROTOCOL_H__
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <glib.h>
23 #include <gio/gio.h>
24
25 #define SESSION_MAC_BUF_SIZE 6
26 #define SESSION_INFO_BUF_SIZE 144
27 #define DEFERRED_INFO_BUF_SIZE 144
28
29 #define ADV
30
31 #ifdef SEEKER
32 #define ROLE "[seeker    ]"
33 #define INFO_MSG ASP_LOGD("%s %s", ROLE, __TIME__)
34 #else
35 #define ROLE "[advertiser]"
36 #define INFO_MSG ASP_LOGD("%s %s", ROLE, __TIME__)
37 #endif
38
39 typedef struct asp_coord_header {
40         guint8 opcode;
41         guint8 seq_num;
42 } __attribute__((packed)) asp_coord_header_s;
43
44 typedef struct asp_request_header {
45         guint8 opcode;
46         guint8 seq_num;
47         guint8 session_mac[SESSION_MAC_BUF_SIZE];
48         guint32 session_id;
49 } __attribute__((packed)) asp_request_header_s;
50
51 typedef struct asp_request_session {
52         guint8 opcode;
53         guint8 seq_num;
54         guint8 session_mac[SESSION_MAC_BUF_SIZE];
55         guint32 session_id;
56         guint32 advertisement_id;
57         guint8 session_information_length;
58         guint8 session_information[SESSION_INFO_BUF_SIZE];
59 } __attribute__((packed)) asp_request_session_s;
60
61 typedef struct asp_added_session {
62         guint8 opcode;
63         guint8 seq_num;
64         guint8 session_mac[SESSION_MAC_BUF_SIZE];
65         guint32 session_id;
66 } __attribute__((packed)) asp_added_session_s;
67
68 typedef struct asp_rejected_session {
69         guint8 opcode;
70         guint8 seq_num;
71         guint8 session_mac[SESSION_MAC_BUF_SIZE];
72         guint32 session_id;
73 } __attribute__((packed)) asp_rejected_session_s;
74
75 typedef struct asp_remove_session {
76         guint8 opcode;
77         guint8 seq_num;
78         guint8 session_mac[SESSION_MAC_BUF_SIZE];
79         guint32 session_id;
80         guint8 reason;
81 } __attribute__((packed)) asp_remove_session_s;
82
83 typedef struct asp_allowed_port {
84         guint8 opcode;
85         guint8 seq_num;
86         guint8 session_mac[SESSION_MAC_BUF_SIZE];
87         guint32 session_id;
88         guint16 port;
89         guint8 proto;
90 } __attribute__((packed)) asp_allowed_port_s;
91
92 typedef struct asp_version {
93         guint8 opcode;
94         guint8 seq_num;
95         guint8 coordination_version;
96         guint8 vendor_information_length;
97         guint32 vendor_information;
98 } __attribute__((packed)) asp_version_s;
99
100 typedef struct asp_deferred_session {
101         guint8 opcode;
102         guint8 seq_num;
103         guint8 session_mac[SESSION_MAC_BUF_SIZE];
104         guint32 session_id;
105         guint8 deferred_session__response_length;
106         guint8 deferred_session__response[DEFERRED_INFO_BUF_SIZE];
107 } __attribute__((packed)) asp_deferred_session_s;
108
109 typedef struct asp_ack {
110         guint8 opcode;
111         guint8 seq_num;
112 } __attribute__((packed)) asp_ack_s;
113
114 typedef struct asp_nack {
115         guint8 opcode;
116         guint8 seq_num;
117         guint8 reason;
118 } __attribute__((packed)) asp_nack_s;
119
120 enum {
121         ASP_OPCODE_REQUEST_SESSION = 0x00,
122         ASP_OPCODE_ADDED_SESSION = 0x01,
123         ASP_OPCODE_REJECTED_SESSION = 0x02,
124
125         ASP_OPCODE_REMOVE_SESSION = 0x03,
126         ASP_OPCODE_ALLOWED_PORT = 0x04,
127         ASP_OPCODE_VERSION = 0x05,
128         ASP_OPCODE_DEFERRED_SESSION = 0x06,
129         ASP_OPCODE_ACK = 0xFE,
130         ASP_OPCODE_NACK = 0xFF
131 };
132
133 enum {
134         ASP_REMOVE_SESS_REASON_UNKOWN_REASON = 0x00,
135         ASP_REMOVE_SESS_REASON_REJECTED_BY_USER = 0x01,
136         ASP_REMOVE_SESS_REASON_ADVERTISED_SERVICE_NOT_AVAILABLE = 0x02,
137         ASP_REMOVE_SESS_REASON_SYSTEM_FAILURE = 0x03
138 };
139
140 enum {
141         ASP_NACK_REASON_INVALID_SESSION_MAC = 0x00,
142         ASP_NACK_REASON_INVALID_SESSION_ID = 0x01,
143         ASP_NACK_REASON_INVALID_OPCODE = 0x02,
144         ASP_NACK_REASON_INVALID_SEQUENCE_NUM = 0x03,
145         ASP_NACK_REASON_NO_SESSION_EXIST = 0x04,
146         ASP_NACK_REASON_UNKNOWN_REASON = 0x05
147 };
148
149 gboolean asp_coordination_protocol_init();
150 gboolean asp_coordination_protocol_destroy();
151 gboolean asp_coordination_protocol_send_msg(GSocketAddress *input_sock_addr,
152                 void *input_data);
153
154 #endif                                                  /* __ASP_COORDINATION_PROTOCOL_H__ */