rsi_91x_pkt.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "rsi_mgmt.h"
  17. /**
  18. * rsi_send_data_pkt() - This function sends the recieved data packet from
  19. * driver to device.
  20. * @common: Pointer to the driver private structure.
  21. * @skb: Pointer to the socket buffer structure.
  22. *
  23. * Return: status: 0 on success, -1 on failure.
  24. */
  25. int rsi_send_data_pkt(struct rsi_common *common, struct sk_buff *skb)
  26. {
  27. struct rsi_hw *adapter = common->priv;
  28. struct ieee80211_hdr *tmp_hdr;
  29. struct ieee80211_tx_info *info;
  30. struct skb_info *tx_params;
  31. struct ieee80211_bss_conf *bss;
  32. int status;
  33. u8 ieee80211_size = MIN_802_11_HDR_LEN;
  34. u8 extnd_size;
  35. __le16 *frame_desc;
  36. u16 seq_num;
  37. info = IEEE80211_SKB_CB(skb);
  38. bss = &info->control.vif->bss_conf;
  39. tx_params = (struct skb_info *)info->driver_data;
  40. if (!bss->assoc) {
  41. status = -EINVAL;
  42. goto err;
  43. }
  44. tmp_hdr = (struct ieee80211_hdr *)&skb->data[0];
  45. seq_num = (le16_to_cpu(tmp_hdr->seq_ctrl) >> 4);
  46. extnd_size = ((uintptr_t)skb->data & 0x3);
  47. if ((FRAME_DESC_SZ + extnd_size) > skb_headroom(skb)) {
  48. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  49. status = -ENOSPC;
  50. goto err;
  51. }
  52. skb_push(skb, (FRAME_DESC_SZ + extnd_size));
  53. frame_desc = (__le16 *)&skb->data[0];
  54. memset((u8 *)frame_desc, 0, FRAME_DESC_SZ);
  55. if (ieee80211_is_data_qos(tmp_hdr->frame_control)) {
  56. ieee80211_size += 2;
  57. frame_desc[6] |= cpu_to_le16(BIT(12));
  58. }
  59. if ((!(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) &&
  60. (common->secinfo.security_enable)) {
  61. if (rsi_is_cipher_wep(common))
  62. ieee80211_size += 4;
  63. else
  64. ieee80211_size += 8;
  65. frame_desc[6] |= cpu_to_le16(BIT(15));
  66. }
  67. frame_desc[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  68. (RSI_WIFI_DATA_Q << 12));
  69. frame_desc[2] = cpu_to_le16((extnd_size) | (ieee80211_size) << 8);
  70. if (common->min_rate != 0xffff) {
  71. /* Send fixed rate */
  72. frame_desc[3] = cpu_to_le16(RATE_INFO_ENABLE);
  73. frame_desc[4] = cpu_to_le16(common->min_rate);
  74. if (conf_is_ht40(&common->priv->hw->conf))
  75. frame_desc[5] = cpu_to_le16(FULL40M_ENABLE);
  76. if (common->vif_info[0].sgi) {
  77. if (common->min_rate & 0x100) /* Only MCS rates */
  78. frame_desc[4] |=
  79. cpu_to_le16(ENABLE_SHORTGI_RATE);
  80. }
  81. }
  82. frame_desc[6] |= cpu_to_le16(seq_num & 0xfff);
  83. frame_desc[7] = cpu_to_le16(((tx_params->tid & 0xf) << 4) |
  84. (skb->priority & 0xf) |
  85. (tx_params->sta_id << 8));
  86. status = adapter->host_intf_write_pkt(common->priv,
  87. skb->data,
  88. skb->len);
  89. if (status)
  90. rsi_dbg(ERR_ZONE, "%s: Failed to write pkt\n",
  91. __func__);
  92. err:
  93. ++common->tx_stats.total_tx_pkt_freed[skb->priority];
  94. rsi_indicate_tx_status(common->priv, skb, status);
  95. return status;
  96. }
  97. /**
  98. * rsi_send_mgmt_pkt() - This functions sends the received management packet
  99. * from driver to device.
  100. * @common: Pointer to the driver private structure.
  101. * @skb: Pointer to the socket buffer structure.
  102. *
  103. * Return: status: 0 on success, -1 on failure.
  104. */
  105. int rsi_send_mgmt_pkt(struct rsi_common *common,
  106. struct sk_buff *skb)
  107. {
  108. struct rsi_hw *adapter = common->priv;
  109. struct ieee80211_hdr *wh;
  110. struct ieee80211_tx_info *info;
  111. struct ieee80211_bss_conf *bss;
  112. struct ieee80211_hw *hw = adapter->hw;
  113. struct ieee80211_conf *conf = &hw->conf;
  114. struct skb_info *tx_params;
  115. int status = -E2BIG;
  116. __le16 *msg;
  117. u8 extnd_size;
  118. u8 vap_id = 0;
  119. info = IEEE80211_SKB_CB(skb);
  120. tx_params = (struct skb_info *)info->driver_data;
  121. extnd_size = ((uintptr_t)skb->data & 0x3);
  122. if (tx_params->flags & INTERNAL_MGMT_PKT) {
  123. if ((extnd_size) > skb_headroom(skb)) {
  124. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  125. dev_kfree_skb(skb);
  126. return -ENOSPC;
  127. }
  128. skb_push(skb, extnd_size);
  129. skb->data[extnd_size + 4] = extnd_size;
  130. status = adapter->host_intf_write_pkt(common->priv,
  131. (u8 *)skb->data,
  132. skb->len);
  133. if (status) {
  134. rsi_dbg(ERR_ZONE,
  135. "%s: Failed to write the packet\n", __func__);
  136. }
  137. dev_kfree_skb(skb);
  138. return status;
  139. }
  140. bss = &info->control.vif->bss_conf;
  141. wh = (struct ieee80211_hdr *)&skb->data[0];
  142. if (FRAME_DESC_SZ > skb_headroom(skb))
  143. goto err;
  144. skb_push(skb, FRAME_DESC_SZ);
  145. memset(skb->data, 0, FRAME_DESC_SZ);
  146. msg = (__le16 *)skb->data;
  147. if (skb->len > MAX_MGMT_PKT_SIZE) {
  148. rsi_dbg(INFO_ZONE, "%s: Dropping mgmt pkt > 512\n", __func__);
  149. goto err;
  150. }
  151. msg[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  152. (RSI_WIFI_MGMT_Q << 12));
  153. msg[1] = cpu_to_le16(TX_DOT11_MGMT);
  154. msg[2] = cpu_to_le16(MIN_802_11_HDR_LEN << 8);
  155. msg[3] = cpu_to_le16(RATE_INFO_ENABLE);
  156. msg[6] = cpu_to_le16(le16_to_cpu(wh->seq_ctrl) >> 4);
  157. if (wh->addr1[0] & BIT(0))
  158. msg[3] |= cpu_to_le16(RSI_BROADCAST_PKT);
  159. if (common->band == NL80211_BAND_2GHZ)
  160. msg[4] = cpu_to_le16(RSI_11B_MODE);
  161. else
  162. msg[4] = cpu_to_le16((RSI_RATE_6 & 0x0f) | RSI_11G_MODE);
  163. if (conf_is_ht40(conf)) {
  164. msg[4] = cpu_to_le16(0xB | RSI_11G_MODE);
  165. msg[5] = cpu_to_le16(0x6);
  166. }
  167. /* Indicate to firmware to give cfm */
  168. if ((skb->data[16] == IEEE80211_STYPE_PROBE_REQ) && (!bss->assoc)) {
  169. msg[1] |= cpu_to_le16(BIT(10));
  170. msg[7] = cpu_to_le16(PROBEREQ_CONFIRM);
  171. common->mgmt_q_block = true;
  172. }
  173. msg[7] |= cpu_to_le16(vap_id << 8);
  174. status = adapter->host_intf_write_pkt(common->priv,
  175. (u8 *)msg,
  176. skb->len);
  177. if (status)
  178. rsi_dbg(ERR_ZONE, "%s: Failed to write the packet\n", __func__);
  179. err:
  180. rsi_indicate_tx_status(common->priv, skb, status);
  181. return status;
  182. }