1 /* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 
13 #ifndef _RMNET_MAP_H_
14 #define _RMNET_MAP_H_
15 
16 struct rmnet_map_control_command {
17 	u8  command_name;
18 	u8  cmd_type:2;
19 	u8  reserved:6;
20 	u16 reserved2;
21 	u32 transaction_id;
22 	union {
23 		struct {
24 			u16 ip_family:2;
25 			u16 reserved:14;
26 			u16 flow_control_seq_num;
27 			u32 qos_id;
28 		} flow_control;
29 		u8 data[0];
30 	};
31 }  __aligned(1);
32 
33 enum rmnet_map_results {
34 	RMNET_MAP_SUCCESS,
35 	RMNET_MAP_CONSUMED,
36 	RMNET_MAP_GENERAL_FAILURE,
37 	RMNET_MAP_NOT_ENABLED,
38 	RMNET_MAP_FAILED_AGGREGATION,
39 	RMNET_MAP_FAILED_MUX
40 };
41 
42 enum rmnet_map_commands {
43 	RMNET_MAP_COMMAND_NONE,
44 	RMNET_MAP_COMMAND_FLOW_DISABLE,
45 	RMNET_MAP_COMMAND_FLOW_ENABLE,
46 	/* These should always be the last 2 elements */
47 	RMNET_MAP_COMMAND_UNKNOWN,
48 	RMNET_MAP_COMMAND_ENUM_LENGTH
49 };
50 
51 struct rmnet_map_header {
52 	u8  pad_len:6;
53 	u8  reserved_bit:1;
54 	u8  cd_bit:1;
55 	u8  mux_id;
56 	u16 pkt_len;
57 }  __aligned(1);
58 
59 #define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \
60 				 (Y)->data)->mux_id)
61 #define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \
62 				(Y)->data)->cd_bit)
63 #define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \
64 				(Y)->data)->pad_len)
65 #define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \
66 				    ((Y)->data + \
67 				      sizeof(struct rmnet_map_header)))
68 #define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \
69 					(Y)->data)->pkt_len))
70 
71 #define RMNET_MAP_COMMAND_REQUEST     0
72 #define RMNET_MAP_COMMAND_ACK         1
73 #define RMNET_MAP_COMMAND_UNSUPPORTED 2
74 #define RMNET_MAP_COMMAND_INVALID     3
75 
76 #define RMNET_MAP_NO_PAD_BYTES        0
77 #define RMNET_MAP_ADD_PAD_BYTES       1
78 
79 u8 rmnet_map_demultiplex(struct sk_buff *skb);
80 struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb);
81 struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb,
82 						  int hdrlen, int pad);
83 void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port);
84 
85 #endif /* _RMNET_MAP_H_ */
86