1 /* Copyright (c) 2013-2018, 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 			__be16 flow_control_seq_num;
27 			__be32 qos_id;
28 		} flow_control;
29 		u8 data[0];
30 	};
31 }  __aligned(1);
32 
33 enum rmnet_map_commands {
34 	RMNET_MAP_COMMAND_NONE,
35 	RMNET_MAP_COMMAND_FLOW_DISABLE,
36 	RMNET_MAP_COMMAND_FLOW_ENABLE,
37 	/* These should always be the last 2 elements */
38 	RMNET_MAP_COMMAND_UNKNOWN,
39 	RMNET_MAP_COMMAND_ENUM_LENGTH
40 };
41 
42 struct rmnet_map_header {
43 	u8  pad_len:6;
44 	u8  reserved_bit:1;
45 	u8  cd_bit:1;
46 	u8  mux_id;
47 	__be16 pkt_len;
48 }  __aligned(1);
49 
50 struct rmnet_map_dl_csum_trailer {
51 	u8  reserved1;
52 	u8  valid:1;
53 	u8  reserved2:7;
54 	u16 csum_start_offset;
55 	u16 csum_length;
56 	__be16 csum_value;
57 } __aligned(1);
58 
59 struct rmnet_map_ul_csum_header {
60 	__be16 csum_start_offset;
61 	u16 csum_insert_offset:14;
62 	u16 udp_ip4_ind:1;
63 	u16 csum_enabled:1;
64 } __aligned(1);
65 
66 #define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \
67 				 (Y)->data)->mux_id)
68 #define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \
69 				(Y)->data)->cd_bit)
70 #define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \
71 				(Y)->data)->pad_len)
72 #define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \
73 				    ((Y)->data + \
74 				      sizeof(struct rmnet_map_header)))
75 #define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \
76 					(Y)->data)->pkt_len))
77 
78 #define RMNET_MAP_COMMAND_REQUEST     0
79 #define RMNET_MAP_COMMAND_ACK         1
80 #define RMNET_MAP_COMMAND_UNSUPPORTED 2
81 #define RMNET_MAP_COMMAND_INVALID     3
82 
83 #define RMNET_MAP_NO_PAD_BYTES        0
84 #define RMNET_MAP_ADD_PAD_BYTES       1
85 
86 struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb,
87 				      struct rmnet_port *port);
88 struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb,
89 						  int hdrlen, int pad);
90 void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port);
91 int rmnet_map_checksum_downlink_packet(struct sk_buff *skb, u16 len);
92 void rmnet_map_checksum_uplink_packet(struct sk_buff *skb,
93 				      struct net_device *orig_dev);
94 
95 #endif /* _RMNET_MAP_H_ */
96