rsi_91x_pkt.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 = NULL;
  29. struct ieee80211_tx_info *info;
  30. struct skb_info *tx_params;
  31. struct ieee80211_bss_conf *bss = NULL;
  32. int status = -EINVAL;
  33. u8 ieee80211_size = MIN_802_11_HDR_LEN;
  34. u8 extnd_size = 0;
  35. __le16 *frame_desc;
  36. u16 seq_num = 0;
  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. goto err;
  42. tmp_hdr = (struct ieee80211_hdr *)&skb->data[0];
  43. seq_num = (le16_to_cpu(tmp_hdr->seq_ctrl) >> 4);
  44. extnd_size = ((uintptr_t)skb->data & 0x3);
  45. if ((FRAME_DESC_SZ + extnd_size) > skb_headroom(skb)) {
  46. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  47. status = -ENOSPC;
  48. goto err;
  49. }
  50. skb_push(skb, (FRAME_DESC_SZ + extnd_size));
  51. frame_desc = (__le16 *)&skb->data[0];
  52. memset((u8 *)frame_desc, 0, FRAME_DESC_SZ);
  53. if (ieee80211_is_data_qos(tmp_hdr->frame_control)) {
  54. ieee80211_size += 2;
  55. frame_desc[6] |= cpu_to_le16(BIT(12));
  56. }
  57. if ((!(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) &&
  58. (common->secinfo.security_enable)) {
  59. if (rsi_is_cipher_wep(common))
  60. ieee80211_size += 4;
  61. else
  62. ieee80211_size += 8;
  63. frame_desc[6] |= cpu_to_le16(BIT(15));
  64. }
  65. frame_desc[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  66. (RSI_WIFI_DATA_Q << 12));
  67. frame_desc[2] = cpu_to_le16((extnd_size) | (ieee80211_size) << 8);
  68. if (common->min_rate != 0xffff) {
  69. /* Send fixed rate */
  70. frame_desc[3] = cpu_to_le16(RATE_INFO_ENABLE);
  71. frame_desc[4] = cpu_to_le16(common->min_rate);
  72. if (conf_is_ht40(&common->priv->hw->conf))
  73. frame_desc[5] = cpu_to_le16(FULL40M_ENABLE);
  74. if (common->vif_info[0].sgi) {
  75. if (common->min_rate & 0x100) /* Only MCS rates */
  76. frame_desc[4] |=
  77. cpu_to_le16(ENABLE_SHORTGI_RATE);
  78. }
  79. }
  80. frame_desc[6] |= cpu_to_le16(seq_num & 0xfff);
  81. frame_desc[7] = cpu_to_le16(((tx_params->tid & 0xf) << 4) |
  82. (skb->priority & 0xf) |
  83. (tx_params->sta_id << 8));
  84. status = adapter->host_intf_write_pkt(common->priv,
  85. skb->data,
  86. skb->len);
  87. if (status)
  88. rsi_dbg(ERR_ZONE, "%s: Failed to write pkt\n",
  89. __func__);
  90. err:
  91. ++common->tx_stats.total_tx_pkt_freed[skb->priority];
  92. rsi_indicate_tx_status(common->priv, skb, status);
  93. return status;
  94. }
  95. /**
  96. * rsi_send_mgmt_pkt() - This functions sends the received management packet
  97. * from driver to device.
  98. * @common: Pointer to the driver private structure.
  99. * @skb: Pointer to the socket buffer structure.
  100. *
  101. * Return: status: 0 on success, -1 on failure.
  102. */
  103. int rsi_send_mgmt_pkt(struct rsi_common *common,
  104. struct sk_buff *skb)
  105. {
  106. struct rsi_hw *adapter = common->priv;
  107. struct ieee80211_hdr *wh = NULL;
  108. struct ieee80211_tx_info *info;
  109. struct ieee80211_bss_conf *bss = NULL;
  110. struct ieee80211_hw *hw = adapter->hw;
  111. struct ieee80211_conf *conf = &hw->conf;
  112. struct skb_info *tx_params;
  113. int status = -E2BIG;
  114. __le16 *msg = NULL;
  115. u8 extnd_size = 0;
  116. u8 vap_id = 0;
  117. info = IEEE80211_SKB_CB(skb);
  118. tx_params = (struct skb_info *)info->driver_data;
  119. extnd_size = ((uintptr_t)skb->data & 0x3);
  120. if (tx_params->flags & INTERNAL_MGMT_PKT) {
  121. if ((extnd_size) > skb_headroom(skb)) {
  122. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
  123. dev_kfree_skb(skb);
  124. return -ENOSPC;
  125. }
  126. skb_push(skb, extnd_size);
  127. skb->data[extnd_size + 4] = extnd_size;
  128. status = adapter->host_intf_write_pkt(common->priv,
  129. (u8 *)skb->data,
  130. skb->len);
  131. if (status) {
  132. rsi_dbg(ERR_ZONE,
  133. "%s: Failed to write the packet\n", __func__);
  134. }
  135. dev_kfree_skb(skb);
  136. return status;
  137. }
  138. bss = &info->control.vif->bss_conf;
  139. wh = (struct ieee80211_hdr *)&skb->data[0];
  140. if (FRAME_DESC_SZ > skb_headroom(skb))
  141. goto err;
  142. skb_push(skb, FRAME_DESC_SZ);
  143. memset(skb->data, 0, FRAME_DESC_SZ);
  144. msg = (__le16 *)skb->data;
  145. if (skb->len > MAX_MGMT_PKT_SIZE) {
  146. rsi_dbg(INFO_ZONE, "%s: Dropping mgmt pkt > 512\n", __func__);
  147. goto err;
  148. }
  149. msg[0] = cpu_to_le16((skb->len - FRAME_DESC_SZ) |
  150. (RSI_WIFI_MGMT_Q << 12));
  151. msg[1] = cpu_to_le16(TX_DOT11_MGMT);
  152. msg[2] = cpu_to_le16(MIN_802_11_HDR_LEN << 8);
  153. msg[3] = cpu_to_le16(RATE_INFO_ENABLE);
  154. msg[6] = cpu_to_le16(le16_to_cpu(wh->seq_ctrl) >> 4);
  155. if (wh->addr1[0] & BIT(0))
  156. msg[3] |= cpu_to_le16(RSI_BROADCAST_PKT);
  157. if (common->band == IEEE80211_BAND_2GHZ)
  158. msg[4] = cpu_to_le16(RSI_11B_MODE);
  159. else
  160. msg[4] = cpu_to_le16((RSI_RATE_6 & 0x0f) | RSI_11G_MODE);
  161. if (conf_is_ht40(conf)) {
  162. msg[4] = cpu_to_le16(0xB | RSI_11G_MODE);
  163. msg[5] = cpu_to_le16(0x6);
  164. }
  165. /* Indicate to firmware to give cfm */
  166. if ((skb->data[16] == IEEE80211_STYPE_PROBE_REQ) && (!bss->assoc)) {
  167. msg[1] |= cpu_to_le16(BIT(10));
  168. msg[7] = cpu_to_le16(PROBEREQ_CONFIRM);
  169. common->mgmt_q_block = true;
  170. }
  171. msg[7] |= cpu_to_le16(vap_id << 8);
  172. status = adapter->host_intf_write_pkt(common->priv,
  173. (u8 *)msg,
  174. skb->len);
  175. if (status)
  176. rsi_dbg(ERR_ZONE, "%s: Failed to write the packet\n", __func__);
  177. err:
  178. rsi_indicate_tx_status(common->priv, skb, status);
  179. return status;
  180. }