1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
5 #include <linux/netdevice.h>
6 #include "rmnet_config.h"
8 #include "rmnet_private.h"
11 static u8 rmnet_map_do_flow_control(struct sk_buff *skb,
12 struct rmnet_port *port,
15 struct rmnet_map_header *map_header = (void *)skb->data;
16 struct rmnet_endpoint *ep;
17 struct net_device *vnd;
21 mux_id = map_header->mux_id;
23 if (mux_id >= RMNET_MAX_LOGICAL_EP) {
25 return RX_HANDLER_CONSUMED;
28 ep = rmnet_get_endpoint(port, mux_id);
31 return RX_HANDLER_CONSUMED;
36 /* Ignore the ip family and pass the sequence number for both v4 and v6
37 * sequence. User space does not support creating dedicated flows for
40 r = rmnet_vnd_do_flow_control(vnd, enable);
43 return RMNET_MAP_COMMAND_UNSUPPORTED;
45 return RMNET_MAP_COMMAND_ACK;
49 static void rmnet_map_send_ack(struct sk_buff *skb,
51 struct rmnet_port *port)
53 struct rmnet_map_header *map_header = (void *)skb->data;
54 struct rmnet_map_control_command *cmd;
55 struct net_device *dev = skb->dev;
57 if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4)
59 skb->len - sizeof(struct rmnet_map_dl_csum_trailer));
61 skb->protocol = htons(ETH_P_MAP);
63 /* Command data immediately follows the MAP header */
64 cmd = (struct rmnet_map_control_command *)(map_header + 1);
65 cmd->cmd_type = type & 0x03;
68 dev->netdev_ops->ndo_start_xmit(skb, dev);
72 /* Process MAP command frame and send N/ACK message as appropriate. Message cmd
73 * name is decoded here and appropriate handler is called.
75 void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
77 struct rmnet_map_header *map_header = (void *)skb->data;
78 struct rmnet_map_control_command *cmd;
79 unsigned char command_name;
82 /* Command data immediately follows the MAP header */
83 cmd = (struct rmnet_map_control_command *)(map_header + 1);
84 command_name = cmd->command_name;
86 switch (command_name) {
87 case RMNET_MAP_COMMAND_FLOW_ENABLE:
88 rc = rmnet_map_do_flow_control(skb, port, 1);
91 case RMNET_MAP_COMMAND_FLOW_DISABLE:
92 rc = rmnet_map_do_flow_control(skb, port, 0);
96 rc = RMNET_MAP_COMMAND_UNSUPPORTED;
100 if (rc == RMNET_MAP_COMMAND_ACK)
101 rmnet_map_send_ack(skb, rc, port);