mac.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: mac.c
  21. *
  22. * Purpose: MAC routines
  23. *
  24. * Author: Tevin Chen
  25. *
  26. * Date: May 21, 1996
  27. *
  28. * Functions:
  29. *
  30. * Revision History:
  31. */
  32. #include "desc.h"
  33. #include "mac.h"
  34. #include "usbpipe.h"
  35. /*
  36. * Description:
  37. * Write MAC Multicast Address Mask
  38. *
  39. * Parameters:
  40. * In:
  41. * mc_filter (mac filter)
  42. * Out:
  43. * none
  44. *
  45. * Return Value: none
  46. *
  47. */
  48. void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
  49. {
  50. __le64 le_mc = cpu_to_le64(mc_filter);
  51. vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
  52. MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc);
  53. }
  54. /*
  55. * Description:
  56. * Shut Down MAC
  57. *
  58. * Parameters:
  59. * In:
  60. * Out:
  61. * none
  62. *
  63. *
  64. */
  65. void vnt_mac_shutdown(struct vnt_private *priv)
  66. {
  67. vnt_control_out(priv, MESSAGE_TYPE_MACSHUTDOWN, 0, 0, 0, NULL);
  68. }
  69. void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
  70. {
  71. u8 data[2];
  72. data[0] = type;
  73. data[1] = EnCFG_BBType_MASK;
  74. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
  75. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  76. }
  77. /*
  78. * Description:
  79. * Disable the Key Entry by MISCFIFO
  80. *
  81. * Parameters:
  82. * In:
  83. * dwIoBase - Base Address for MAC
  84. *
  85. * Out:
  86. * none
  87. *
  88. * Return Value: none
  89. *
  90. */
  91. void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
  92. {
  93. vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
  94. sizeof(entry_idx), &entry_idx);
  95. }
  96. /*
  97. * Description:
  98. * Set the Key by MISCFIFO
  99. *
  100. * Parameters:
  101. * In:
  102. * dwIoBase - Base Address for MAC
  103. *
  104. * Out:
  105. * none
  106. *
  107. * Return Value: none
  108. *
  109. */
  110. void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
  111. u32 key_idx, u8 *addr, u8 *key)
  112. {
  113. struct vnt_mac_set_key set_key;
  114. u16 offset;
  115. offset = MISCFIFO_KEYETRY0;
  116. offset += (entry_idx * MISCFIFO_KEYENTRYSIZE);
  117. set_key.u.write.key_ctl = cpu_to_le16(key_ctl);
  118. memcpy(set_key.u.write.addr, addr, ETH_ALEN);
  119. /* swap over swap[0] and swap[1] to get correct write order */
  120. swap(set_key.u.swap[0], set_key.u.swap[1]);
  121. memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
  122. dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
  123. offset, key_ctl, (u8 *)&set_key);
  124. vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
  125. (u16)key_idx, sizeof(struct vnt_mac_set_key), (u8 *)&set_key);
  126. }
  127. void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  128. {
  129. u8 data[2];
  130. data[0] = 0;
  131. data[1] = bits;
  132. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  133. reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  134. }
  135. void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
  136. {
  137. u8 data[2];
  138. data[0] = bits;
  139. data[1] = bits;
  140. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  141. reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  142. }
  143. void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
  144. {
  145. u8 data[2];
  146. data[0] = (u8)(word & 0xff);
  147. data[1] = (u8)(word >> 8);
  148. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  149. reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  150. }
  151. void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
  152. {
  153. vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
  154. MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
  155. }
  156. void vnt_mac_enable_protect_mode(struct vnt_private *priv)
  157. {
  158. u8 data[2];
  159. data[0] = EnCFG_ProtectMd;
  160. data[1] = EnCFG_ProtectMd;
  161. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  162. MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  163. }
  164. void vnt_mac_disable_protect_mode(struct vnt_private *priv)
  165. {
  166. u8 data[2];
  167. data[0] = 0;
  168. data[1] = EnCFG_ProtectMd;
  169. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  170. MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  171. }
  172. void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
  173. {
  174. u8 data[2];
  175. data[0] = EnCFG_BarkerPream;
  176. data[1] = EnCFG_BarkerPream;
  177. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  178. MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  179. }
  180. void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
  181. {
  182. u8 data[2];
  183. data[0] = 0;
  184. data[1] = EnCFG_BarkerPream;
  185. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
  186. MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  187. }
  188. void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
  189. {
  190. u8 data[2];
  191. data[0] = (u8)(interval & 0xff);
  192. data[1] = (u8)(interval >> 8);
  193. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  194. MAC_REG_BI, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  195. }
  196. void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
  197. {
  198. u8 data[2];
  199. data[0] = led;
  200. data[1] = state;
  201. vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
  202. MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
  203. }