rmnet_map_command.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #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 *rdinfo,
  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 = &rdinfo->muxed_ep[mux_id];
  36. vnd = ep->egress_dev;
  37. ip_family = cmd->flow_control.ip_family;
  38. fc_seq = ntohs(cmd->flow_control.flow_control_seq_num);
  39. qos_id = ntohl(cmd->flow_control.qos_id);
  40. /* Ignore the ip family and pass the sequence number for both v4 and v6
  41. * sequence. User space does not support creating dedicated flows for
  42. * the 2 protocols
  43. */
  44. r = rmnet_vnd_do_flow_control(vnd, enable);
  45. if (r) {
  46. kfree_skb(skb);
  47. return RMNET_MAP_COMMAND_UNSUPPORTED;
  48. } else {
  49. return RMNET_MAP_COMMAND_ACK;
  50. }
  51. }
  52. static void rmnet_map_send_ack(struct sk_buff *skb,
  53. unsigned char type)
  54. {
  55. struct rmnet_map_control_command *cmd;
  56. int xmit_status;
  57. skb->protocol = htons(ETH_P_MAP);
  58. cmd = RMNET_MAP_GET_CMD_START(skb);
  59. cmd->cmd_type = type & 0x03;
  60. netif_tx_lock(skb->dev);
  61. xmit_status = skb->dev->netdev_ops->ndo_start_xmit(skb, skb->dev);
  62. netif_tx_unlock(skb->dev);
  63. }
  64. /* Process MAP command frame and send N/ACK message as appropriate. Message cmd
  65. * name is decoded here and appropriate handler is called.
  66. */
  67. rx_handler_result_t rmnet_map_command(struct sk_buff *skb,
  68. struct rmnet_port *port)
  69. {
  70. struct rmnet_map_control_command *cmd;
  71. unsigned char command_name;
  72. unsigned char rc = 0;
  73. cmd = RMNET_MAP_GET_CMD_START(skb);
  74. command_name = cmd->command_name;
  75. switch (command_name) {
  76. case RMNET_MAP_COMMAND_FLOW_ENABLE:
  77. rc = rmnet_map_do_flow_control(skb, port, 1);
  78. break;
  79. case RMNET_MAP_COMMAND_FLOW_DISABLE:
  80. rc = rmnet_map_do_flow_control(skb, port, 0);
  81. break;
  82. default:
  83. rc = RMNET_MAP_COMMAND_UNSUPPORTED;
  84. kfree_skb(skb);
  85. break;
  86. }
  87. if (rc == RMNET_MAP_COMMAND_ACK)
  88. rmnet_map_send_ack(skb, rc);
  89. return RX_HANDLER_CONSUMED;
  90. }