blob: c8248ce66969567d40f235debc22238313419194 [file] [log] [blame]
Ravinder Konka94266eb2015-10-15 19:55:24 +05301/******************************************************************
2 * Copyright (c) 2013-2015,2017, The Linux Foundation. All rights reserved.
3
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 * See the GNU General Public License for more details.
12 *---------------------------------------------------------------
13
14 * DESCRIPTION
15 * Header file for eMBMs Tunneling Module in kernel.
16 *******************************************************************
17 */
18
19#ifndef EMBMS_H
20#define EMBMS_H
21
22#include <linux/ioctl.h>
23#include <stdbool.h>
24#include <linux/if_addr.h>
25#include <linux/list.h>
26#include <linux/ip.h>
27#include <linux/miscdevice.h>
28#include <linux/spinlock.h>
29#include <linux/cdev.h>
30
31#define EMBMS_MAX_IFACE_NAME 20
32
33/* Defining IP and UDP header related macros*/
34
35#define UDP_CHECKSUM 0
36#define IP_VERSION 4
37#define IP_IHL 5
38#define IP_TOS 0
39#define IP_ID 1
40#define IP_FRAG_OFFSET htons(0x4000)
41#define IP_TTL 64
42#define BRIDGE_IFACE "bridge0"
43
44#define BUF_LEN 1024
45#define TUNNELING_ON 1
46#define TUNNELING_OFF 0
47
48// definitions required for IOCTL
49static unsigned int dev_num = 1;
50/* Embms device used for communication*/
51struct cdev embms_device;
52static struct class *embms_class;
53static dev_t device;
54#define EMBMS_IOC_MAGIC 0x64
55
56#define embms_debug pr_debug
57#define embms_error pr_debug
58
59/* The name of the device file*/
60#define EMBMS_DEVICE_NAME "embms_tm_device"
61
62extern int (*embms_tm_multicast_recv)(struct sk_buff *skb);
63
64/**
65 * enum embms_action_type - Describes action to perform
66 * @ADD_CLIENT_ENTRY: add client entry to TMGI
67 * @DELETE_CLIENT_ENTRY: deelte client entry from TMGI
68 * @TMGI_DEACTIVATE: Delete TMGI entry
69 * @CLIENT_ACTIVATE_ALL_TMGI: Add client to all TMGI
70 * @CLIENT_DEACTIVATE_ALL_TMGI: Delete client from all TMGI
71 * @SESSION_DEACTIVATE: Stop session
72 * @SOCK_INFO: Socket information like V4 addr, port etc
73 *
74 * This enum defines the types of action which are
75 * supported by this module.
76 */
77
78enum {
79 ADD_CLIENT_ENTRY = 0,
80 DELETE_CLIENT_ENTRY,
81 TMGI_DEACTIVATE,
82 CLIENT_ACTIVATE_ALL_TMGI,
83 CLIENT_DEACTIVATE_ALL_TMGI,
84 SESSION_DEACTIVATE,
85 SOCK_INFO
86} embms_action_type;
87
88/**
89 * struct tmgi_to_clnt_info_update - information for addition/deletion
90 * @multicast_addr: TMGI multicast IP to receive data
91 * @multicast_port: TMGI multicast port to receive date
92 * @client_addr: Client IPV4 address for sending data
93 * @client_port: Client port for sending data
94 * @data_port: port used to send data to client
95 * @action_type: Action to be performed
96 * @iface_name: iface to listen to for data
97 *
98 * This structure contains information as to what action
99 * needs to be performed on TMGI-client table. It is
100 * sent as a parameter during an IOCTL call
101 */
102
103struct tmgi_to_clnt_info_update {
104 u32 multicast_addr;
105 u16 multicast_port;
106 u32 client_addr;
107 u16 client_port;
108 u16 data_port;
109 u32 action_type;
110 char iface_name[EMBMS_MAX_IFACE_NAME];
111};
112
113/**
114 * struct clnt_info - contains client information
115 * @addr: Client IPV4 address for sending packets
116 * @port: Client port for sending packets
117 * @dmac: Client DMAC address
118 * @client_list_ptr : list ptr used to maintain client list
119 *
120 * This structure maintains complete client information
121 * to be used when sending packets to client
122 */
123
124struct clnt_info {
125 u32 addr;
126 u16 port;
127 u8 dmac[ETH_ALEN];
128 struct list_head client_list_ptr;
129};
130
131/**
132 * struct tmgi_to_clnt_info - contains TMGI information
133 * @tmgi_multicast_addr: TMGI IPV4 address to listen for packets
134 * @tmgi_port: Client port to listen for packets
135 * @no_of_clients: No of clients for a TMGI
136 * @client_list_head : list head for client list
137 * @tmgi_list_ptr : list ptr to maintain tmgi list
138 *
139 * This structure maintains complete client information
140 * to be used when sending data to client
141 */
142
143struct tmgi_to_clnt_info {
144 u32 tmgi_multicast_addr;
145 u16 tmgi_port;
146 u16 no_of_clients;
147 struct list_head client_list_head;
148 struct list_head tmgi_list_ptr;
149};
150
151/**
152 * struct embms_info_internal - stores module specific params
153 * @device_under_use: Used to prevent concurent access to the same device
154 * @embms_data_port: Source Data port used for tunnelled packets
155 * @embms_iface: Iface to receive embms traffic
156 * @embms_tunneling_status : Current EMBMS Status
157 * @no_of_tmgi_sessions : Number of current active TMGI sessions
158 * @lock : Lock for concurrency scenarios
159 * @ip_ident : IP identification number to be used for sent packets
160 *
161 * This tructure holds module specific information which is
162 * used throughout the module to maintain consistency
163 */
164
165struct embms_info_internal {
166 atomic_t device_under_use;
167 int embms_data_port;
168 char embms_iface[EMBMS_MAX_IFACE_NAME];
169 int embms_tunneling_status;
170 int no_of_tmgi_sessions;
171 /*lock to prevent concurrent access*/
172 spinlock_t lock;
173 atomic_t ip_ident;
174};
175
176/* This ioctl is used to add a new client entry to tunneling module.
177 * Entry params are populated in the struct used for ioctl
178 */
179
180#define ADD_EMBMS_TUNNEL _IOW(EMBMS_IOC_MAGIC, 0, \
181 struct tmgi_to_clnt_info_update)
182
183/* This ioctl is used to delete a client entry for a particular
184 * TMGI from tunneling module.
185 * Entry params are populated in the struct used for ioctl
186 */
187
188#define DEL_EMBMS_TUNNEL _IOW(EMBMS_IOC_MAGIC, 1, \
189 struct tmgi_to_clnt_info_update)
190
191/* This ioctl is used to delete a TMGI entry completely
192 * from tunneling module.
193 * Entry params are populated in the struct used for ioctl
194 */
195
196#define TMGI_DEACTIVATE _IOW(EMBMS_IOC_MAGIC, 2, \
197 struct tmgi_to_clnt_info_update)
198
199/* This ioctl is used to delete client entry completely
200 * from tunneling module.
201 * Entry params are populated in the struct used for ioctl
202 */
203
204#define CLIENT_DEACTIVATE _IOW(EMBMS_IOC_MAGIC, 3, \
205 struct tmgi_to_clnt_info_update)
206
207/* Gets the ON/OFF status of Tunneling module*/
208
209#define GET_EMBMS_TUNNELING_STATUS _IO(EMBMS_IOC_MAGIC, 4)
210
211/* Used to start tunneling. Argument is the port
212 * number to be used to send
213 * data to clients
214 */
215
216#define START_EMBMS_TUNNEL _IOW(EMBMS_IOC_MAGIC, 5, \
217 struct tmgi_to_clnt_info_update)
218
219/* Used to stop tunnleing*/
220
221#define STOP_EMBMS_TUNNEL _IO(EMBMS_IOC_MAGIC, 6)
222
223/* Return values indicating error status*/
224#define SUCCESS 0 /* Successful operation*/
225#define FAILURE -1 /* Unsuccessful operation*/
226
227/* Error Condition Values*/
228#define ENOMEM -2 /* Out of memory*/
229#define EBADPARAM -3 /* Incorrect parameters passed*/
230#define ENOEFFECT -4 /* No Effect*/
231
232#endif
233