rmnet_map_command.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include <linux/netdevice.h>
  13. #include "rmnet_config.h"
  14. #include "rmnet_map.h"
  15. #include "rmnet_private.h"
  16. #include "rmnet_vnd.h"
  17. static u8 rmnet_map_do_flow_control(struct sk_buff *skb,
  18. struct rmnet_port *port,
  19. int enable)
  20. {
  21. struct rmnet_map_control_command *cmd;
  22. struct rmnet_endpoint *ep;
  23. struct net_device *vnd;
  24. u16 ip_family;
  25. u16 fc_seq;
  26. u32 qos_id;
  27. u8 mux_id;
  28. int r;
  29. mux_id = RMNET_MAP_GET_MUX_ID(skb);
  30. cmd = RMNET_MAP_GET_CMD_START(skb);
  31. if (mux_id >= RMNET_MAX_LOGICAL_EP) {
  32. kfree_skb(skb);
  33. return RX_HANDLER_CONSUMED;
  34. }
  35. ep = rmnet_get_endpoint(port, mux_id);
  36. if (!ep) {
  37. kfree_skb(skb);
  38. return RX_HANDLER_CONSUMED;
  39. }
  40. vnd = ep->egress_dev;
  41. ip_family = cmd->flow_control.ip_family;
  42. fc_seq = ntohs(cmd->flow_control.flow_control_seq_num);
  43. qos_id = ntohl(cmd->flow_control.qos_id);
  44. /* Ignore the ip family and pass the sequence number for both v4 and v6
  45. * sequence. User space does not support creating dedicated flows for
  46. * the 2 protocols
  47. */
  48. r = rmnet_vnd_do_flow_control(vnd, enable);
  49. if (r) {
  50. kfree_skb(skb);
  51. return RMNET_MAP_COMMAND_UNSUPPORTED;
  52. } else {
  53. return RMNET_MAP_COMMAND_ACK;
  54. }
  55. }
  56. static void rmnet_map_send_ack(struct sk_buff *skb,
  57. unsigned char type,
  58. struct rmnet_port *port)
  59. {
  60. struct rmnet_map_control_command *cmd;
  61. struct net_device *dev = skb->dev;
  62. if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4)
  63. skb_trim(skb,
  64. skb->len - sizeof(struct rmnet_map_dl_csum_trailer));
  65. skb->protocol = htons(ETH_P_MAP);
  66. cmd = RMNET_MAP_GET_CMD_START(skb);
  67. cmd->cmd_type = type & 0x03;
  68. netif_tx_lock(dev);
  69. dev->netdev_ops->ndo_start_xmit(skb, dev);
  70. netif_tx_unlock(dev);
  71. }
  72. /* Process MAP command frame and send N/ACK message as appropriate. Message cmd
  73. * name is decoded here and appropriate handler is called.
  74. */
  75. void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
  76. {
  77. struct rmnet_map_control_command *cmd;
  78. unsigned char command_name;
  79. unsigned char rc = 0;
  80. cmd = RMNET_MAP_GET_CMD_START(skb);
  81. command_name = cmd->command_name;
  82. switch (command_name) {
  83. case RMNET_MAP_COMMAND_FLOW_ENABLE:
  84. rc = rmnet_map_do_flow_control(skb, port, 1);
  85. break;
  86. case RMNET_MAP_COMMAND_FLOW_DISABLE:
  87. rc = rmnet_map_do_flow_control(skb, port, 0);
  88. break;
  89. default:
  90. rc = RMNET_MAP_COMMAND_UNSUPPORTED;
  91. kfree_skb(skb);
  92. break;
  93. }
  94. if (rc == RMNET_MAP_COMMAND_ACK)
  95. rmnet_map_send_ack(skb, rc, port);
  96. }