plc.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * plc.c - Qualcomm Atheros Powerline Data Structure;
  44. *
  45. * this structure contains information needed to perform various
  46. * operations on Qualcomm Atheros powerline devices; it represents
  47. * one instance of a device and could easily be converted to an
  48. * object in the future;
  49. *
  50. * this structure points to a channel and a message structure;
  51. *
  52. *
  53. * Contributor(s):
  54. * Charles Maier
  55. * Alex Vasquez
  56. *
  57. *--------------------------------------------------------------------*/
  58. #ifndef PLC_SOURCE
  59. #define PLC_SOURCE
  60. #include "../plc/plc.h"
  61. #include "../ether/channel.h"
  62. struct plc plc =
  63. {
  64. (struct channel *) (& channel),
  65. (struct message *) (0),
  66. (void *) (0),
  67. 0,
  68. /*
  69. * Local Device Address (LDA) buffer needed by all operations;
  70. */
  71. {
  72. 0x00,
  73. 0x00,
  74. 0x00,
  75. 0x00,
  76. 0x00,
  77. 0x00
  78. },
  79. /*
  80. * Remote Device Address (RDA) buffer needed by selected operations;
  81. */
  82. {
  83. 0x00,
  84. 0x00,
  85. 0x00,
  86. 0x00,
  87. 0x00,
  88. 0x00
  89. },
  90. /*
  91. * Network Membership Key (NMK) needed by VS_SET_KEY operations;
  92. * The default is an encrypted version of password "HomePlugAV";
  93. */
  94. {
  95. 0x50,
  96. 0xD3,
  97. 0xE4,
  98. 0x93,
  99. 0x3F,
  100. 0x85,
  101. 0x5B,
  102. 0x70,
  103. 0x40,
  104. 0x78,
  105. 0x4D,
  106. 0xF8,
  107. 0x15,
  108. 0xAA,
  109. 0x8D,
  110. 0xB7
  111. },
  112. /*
  113. * Device Access Key (DAK) needed for VS_SET_KEY operations;
  114. * The default is an encrypted version of password "HomePlugAV";
  115. */
  116. {
  117. 0x68,
  118. 0x9F,
  119. 0x07,
  120. 0x4B,
  121. 0x8B,
  122. 0x02,
  123. 0x75,
  124. 0xA2,
  125. 0x71,
  126. 0x0B,
  127. 0x0B,
  128. 0x57,
  129. 0x79,
  130. 0xAD,
  131. 0x16,
  132. 0x30
  133. },
  134. /*
  135. * struct _file_ CFG; MAC software will be read from this file and
  136. * written to RAM for each device specified on the command line;
  137. * some tools use this file for the panther/lynx softloader;
  138. */
  139. {
  140. (file_t) (-1),
  141. (char const *) (0)
  142. },
  143. /*
  144. * struct _file_ cfg; SDRAM configuration will be read from flash
  145. * on the specified device and written to this file;
  146. */
  147. {
  148. (file_t) (-1),
  149. (char const *) (0)
  150. },
  151. /*
  152. * struct _file_ SFT; softloader file to be written to flash
  153. * memory;
  154. */
  155. {
  156. (file_t) (-1),
  157. (char const *) (0)
  158. },
  159. /*
  160. * struct _file_ sft; softloader file to be read from flash
  161. * memory;
  162. */
  163. {
  164. (file_t) (-1),
  165. (char const *) (0)
  166. },
  167. /*
  168. * struct _file_ NVM; runtime firmware will be read from this file
  169. * and written to RAM for each device specified on the command line;
  170. */
  171. {
  172. (file_t) (-1),
  173. (char const *) (0)
  174. },
  175. /*
  176. * struct _file_ nvm; MAC software will be read from SDRAM on the
  177. * specified device and written to this file; interlocks elsewhere
  178. * in the code should prevent this file from being overwritten
  179. * multiple times, by accident, and ensure that it is created before
  180. * and new MAC software is written to device RAM;
  181. */
  182. {
  183. (file_t) (-1),
  184. (char const *) (0)
  185. },
  186. /*
  187. * struct _file_ PIB; PIB information will be read from this file
  188. * and written to RAM for each device specified on the command line;
  189. */
  190. {
  191. (file_t) (-1),
  192. (char const *) (0)
  193. },
  194. /*
  195. * struct _file_ pib; PIB information will be read from SDRAM on
  196. * the specified device and written to this file; interlocks elsewhere
  197. * in the code should prevent this file from being overwritten
  198. * multiple times, by accident, and ensure that it is created before
  199. * any new PIB software is written to device RAM;
  200. */
  201. {
  202. (file_t) (-1),
  203. (char const *) (0)
  204. },
  205. /*
  206. * struct _file_ XML; optional XML PIB edit instructions; this is an
  207. * advanced feature;
  208. */
  209. {
  210. (file_t) (-1),
  211. (char const *) (0)
  212. },
  213. /*
  214. * struct _file_ rpt; Watchdog Report data will be read from the device
  215. * and written to this file;
  216. */
  217. {
  218. (file_t) (-1),
  219. (char const *) (0)
  220. },
  221. /*
  222. * struct _file_ socket;
  223. */
  224. {
  225. (file_t) (-1),
  226. (char const *) (0)
  227. },
  228. /*
  229. * miscellaneous small integers used as needed when arguments
  230. * are required for an MME;
  231. */
  232. HARDWAREID,
  233. SOFTWAREID,
  234. PLCSESSION,
  235. HOSTACTION,
  236. SECTORCODE,
  237. MODULECODE,
  238. PUSHBUTTON,
  239. READACTION,
  240. PLCOUPLING,
  241. FLASH_SIZE,
  242. /*
  243. * various boolean flags; bailout causes exit on first failure;
  244. * timeout indicates a real timeout; count is the loop counter;
  245. * pause is a loop wait timer; values are declared as constants
  246. * above;
  247. */
  248. PLC_STATE,
  249. PLC_TIMER,
  250. PLC_SLEEP,
  251. PLC_COUNT,
  252. PLC_INDEX,
  253. PLC_FLAGS,
  254. PLC_FLAGS
  255. };
  256. #if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
  257. #define RANDOMIZE_COOKIE 1
  258. #endif
  259. #ifdef RANDOMIZE_COOKIE
  260. {
  261. int f;
  262. f = open("/dev/urandom", O_BINARY|O_RDONLY);
  263. if (f >= 0) {
  264. do {
  265. read(f, &plc.cookie, sizeof plc.cookie);
  266. } while (plc.cookie == PLCSESSION || plc.cookie == 0 || plc.cookie == 0xFFFFFFFF);
  267. close(f);
  268. }
  269. }
  270. #endif
  271. #endif