rmnet_map_command.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. int xmit_status;
  62. if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) {
  63. if (skb->len < sizeof(struct rmnet_map_header) +
  64. RMNET_MAP_GET_LENGTH(skb) +
  65. sizeof(struct rmnet_map_dl_csum_trailer)) {
  66. kfree_skb(skb);
  67. return;
  68. }
  69. skb_trim(skb, skb->len -
  70. sizeof(struct rmnet_map_dl_csum_trailer));
  71. }
  72. skb->protocol = htons(ETH_P_MAP);
  73. cmd = RMNET_MAP_GET_CMD_START(skb);
  74. cmd->cmd_type = type & 0x03;
  75. netif_tx_lock(skb->dev);
  76. xmit_status = skb->dev->netdev_ops->ndo_start_xmit(skb, skb->dev);
  77. netif_tx_unlock(skb->dev);
  78. }
  79. /* Process MAP command frame and send N/ACK message as appropriate. Message cmd
  80. * name is decoded here and appropriate handler is called.
  81. */
  82. void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
  83. {
  84. struct rmnet_map_control_command *cmd;
  85. unsigned char command_name;
  86. unsigned char rc = 0;
  87. cmd = RMNET_MAP_GET_CMD_START(skb);
  88. command_name = cmd->command_name;
  89. switch (command_name) {
  90. case RMNET_MAP_COMMAND_FLOW_ENABLE:
  91. rc = rmnet_map_do_flow_control(skb, port, 1);
  92. break;
  93. case RMNET_MAP_COMMAND_FLOW_DISABLE:
  94. rc = rmnet_map_do_flow_control(skb, port, 0);
  95. break;
  96. default:
  97. rc = RMNET_MAP_COMMAND_UNSUPPORTED;
  98. kfree_skb(skb);
  99. break;
  100. }
  101. if (rc == RMNET_MAP_COMMAND_ACK)
  102. rmnet_map_send_ack(skb, rc, port);
  103. }