PLCTopology.c.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. PLCTopology.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='plctool.c.html' title=' plctool.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='PLCTopologyPrint.c.html' title=' PLCTopologyPrint.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * PLCTopology.c
  64. *
  65. * plc.h
  66. *
  67. *
  68. * Contributor(s):
  69. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  70. * Matthieu Poullet &lt;m.poullet@avm.de&gt;
  71. *
  72. *--------------------------------------------------------------------*/
  73. #ifndef PLCTOPOLOGY_SOURCE
  74. #define PLCTOPOLOGY_SOURCE
  75. #include &lt;memory.h&gt;
  76. #include &lt;errno.h&gt;
  77. #include &quot;../tools/memory.h&quot;
  78. #include &quot;../tools/symbol.h&quot;
  79. #include &quot;../tools/error.h&quot;
  80. #include &quot;../tools/flags.h&quot;
  81. #include &quot;../plc/plc.h&quot;
  82. /*====================================================================*
  83. *
  84. * signed PLCPlatform (struct channel * channel, struct plcstation * station);
  85. *
  86. * populate plcstation structure with hardware and firmware version
  87. * string using a VS_SW_VER message;
  88. *
  89. * extern char const * chipset [] contains chipset name strings in
  90. * order of chipset code but function chipset() must be called to
  91. * insert the true code into the confirmation message because some
  92. * chipsets return the wrong code; alien technology and voodoo are
  93. * needed;
  94. *
  95. *--------------------------------------------------------------------*/
  96. static signed PLCPlatform (struct channel * channel, struct plcstation * plcstation)
  97. {
  98. struct message message;
  99. ssize_t packetsize;
  100. #ifndef __GNUC__
  101. #pragma pack (push,1)
  102. #endif
  103. struct __packed vs_sw_ver_request
  104. {
  105. struct ethernet_hdr ethernet;
  106. struct qualcomm_hdr qualcomm;
  107. }
  108. * request = (struct vs_sw_ver_request *) (&amp;message);
  109. struct __packed vs_sw_ver_confirm
  110. {
  111. struct ethernet_hdr ethernet;
  112. struct qualcomm_hdr qualcomm;
  113. uint8_t MSTATUS;
  114. uint8_t MDEVICE;
  115. uint8_t MLENGTH;
  116. char MSTRING [0x80];
  117. }
  118. * confirm = (struct vs_sw_ver_confirm *) (&amp;message);
  119. #ifndef __GNUC__
  120. #pragma pack (pop)
  121. #endif
  122. memset (&amp;message, 0, sizeof (message));
  123. EthernetHeader (&amp;request-&gt;ethernet, plcstation-&gt;MAC, channel-&gt;host, channel-&gt;type);
  124. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
  125. if (sendpacket (channel, &amp;message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) &gt; 0)
  126. {
  127. while ((packetsize = readpacket (channel, &amp;message, sizeof (message))) &gt; 0)
  128. {
  129. if (!UnwantedMessage (&amp;message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF)))
  130. {
  131. chipset (confirm);
  132. strncpy (plcstation-&gt;hardware, chipsetname (confirm-&gt;MDEVICE), sizeof (plcstation-&gt;hardware));
  133. strncpy (plcstation-&gt;firmware, confirm-&gt;MSTRING, sizeof (plcstation-&gt;firmware));
  134. return (0);
  135. }
  136. }
  137. }
  138. return (-1);
  139. }
  140. /*====================================================================*
  141. *
  142. * signed PLCIdentity (struct channel * channel, struct plcstation * station);
  143. *
  144. * populate plcstation structure with the device identity using a
  145. * VS_MFG_STRING message;
  146. *
  147. *--------------------------------------------------------------------*/
  148. static signed PLCIdentity (struct channel * channel, struct plcstation * plcstation)
  149. {
  150. struct message message;
  151. ssize_t packetsize;
  152. #ifndef __GNUC__
  153. #pragma pack (push,1)
  154. #endif
  155. struct __packed vs_mfg_string_request
  156. {
  157. struct ethernet_hdr ethernet;
  158. struct qualcomm_hdr qualcomm;
  159. }
  160. * request = (struct vs_mfg_string_request *) (&amp;message);
  161. struct __packed vs_mfg_string_confirm
  162. {
  163. struct ethernet_hdr ethernet;
  164. struct qualcomm_hdr qualcomm;
  165. uint8_t MSTATUS;
  166. uint8_t MLENGTH;
  167. char MSTRING [0x40];
  168. }
  169. * confirm = (struct vs_mfg_string_confirm *) (&amp;message);
  170. #ifndef __GNUC__
  171. #pragma pack (pop)
  172. #endif
  173. memset (&amp;message, 0, sizeof (message));
  174. EthernetHeader (&amp;request-&gt;ethernet, plcstation-&gt;MAC, channel-&gt;host, channel-&gt;type);
  175. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_MFG_STRING | MMTYPE_REQ));
  176. if (sendpacket (channel, &amp;message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) &gt; 0)
  177. {
  178. while ((packetsize = readpacket (channel, &amp;message, sizeof (message))) &gt; 0)
  179. {
  180. if (!UnwantedMessage (&amp;message, packetsize, 0, (VS_MFG_STRING | MMTYPE_CNF)))
  181. {
  182. strncpy (plcstation-&gt;identity, confirm-&gt;MSTRING, sizeof (plcstation-&gt;identity));
  183. return (0);
  184. }
  185. }
  186. }
  187. return (-1);
  188. }
  189. /*====================================================================*
  190. *
  191. * signed PLCTopology (struct channel * channel, struct message * message, struct plctopology * plctopology)
  192. *
  193. * populate a plctopology structure with network information; the
  194. * logic this is elusive due to the way the VS_NW_INFO message is
  195. * structured;
  196. *
  197. * the host can have many interfaces and each interface can have
  198. * many powerline devices connected to it; each powerline device
  199. * can bridge to an independent powerline network having a unique
  200. * set of member devices; alternately, some powerline devices can
  201. * be members of the same powerline network;
  202. *
  203. * INT6x00 chipsets have an 8-bit PHY rate while AR7x00 chipsets
  204. * have a 16-bit PHY rate; this means that AR7x00 PHY rates need
  205. *
  206. *--------------------------------------------------------------------*/
  207. signed PLCTopology (struct channel * channel, struct message * message, struct plctopology * plctopology)
  208. {
  209. ssize_t packetsize;
  210. #if defined(INT6x00)
  211. struct __packed vs_nw_info_request
  212. {
  213. struct ethernet_hdr ethernet;
  214. struct qualcomm_hdr qualcomm;
  215. }
  216. * request = (struct vs_nw_info_request *)(message);
  217. struct __packed vs_nw_info_confirm
  218. {
  219. struct ethernet_hdr ethernet;
  220. struct qualcomm_hdr qualcomm;
  221. uint8_t data [1];
  222. }
  223. * confirm = (struct vs_nw_info_confirm *)(message);
  224. struct __packed station
  225. {
  226. uint8_t MAC [ETHER_ADDR_LEN];
  227. uint8_t TEI;
  228. uint8_t BDA [ETHER_ADDR_LEN];
  229. uint8_t AVGTX;
  230. uint8_t AVGRX;
  231. }
  232. * station;
  233. struct __packed network
  234. {
  235. uint8_t NID [7];
  236. uint8_t SNID;
  237. uint8_t TEI;
  238. uint8_t ROLE;
  239. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  240. uint8_t CCO_TEI;
  241. uint8_t NUMSTAS;
  242. struct station stations [1];
  243. }
  244. * network;
  245. struct __packed networks
  246. {
  247. uint8_t NUMAVLNS;
  248. struct network networks [1];
  249. }
  250. * networks = (struct networks *) (confirm-&gt;data);
  251. #elif defined (AR7x00)
  252. struct __packed vs_nw_info_request
  253. {
  254. struct ethernet_hdr ethernet;
  255. struct qualcomm_fmi qualcomm;
  256. }
  257. * request = (struct vs_nw_info_request *)(message);
  258. struct __packed vs_nw_info_confirm
  259. {
  260. struct ethernet_hdr ethernet;
  261. struct qualcomm_fmi qualcomm;
  262. uint8_t SUB_VERSION;
  263. uint8_t Reserved;
  264. uint16_t DATA_LEN;
  265. uint8_t DATA [1];
  266. }
  267. * confirm = (struct vs_nw_info_confirm *)(message);
  268. struct __packed station
  269. {
  270. uint8_t MAC [ETHER_ADDR_LEN];
  271. uint8_t TEI;
  272. uint8_t Reserved [3];
  273. uint8_t BDA [ETHER_ADDR_LEN];
  274. uint16_t AVGTX;
  275. uint8_t COUPLING;
  276. uint8_t Reserved3;
  277. uint16_t AVGRX;
  278. uint16_t Reserved4;
  279. }
  280. * station;
  281. struct __packed network
  282. {
  283. uint8_t NID [7];
  284. uint8_t Reserved1 [2];
  285. uint8_t SNID;
  286. uint8_t TEI;
  287. uint8_t Reserved2 [4];
  288. uint8_t ROLE;
  289. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  290. uint8_t CCO_TEI;
  291. uint8_t Reserved3 [3];
  292. uint8_t NUMSTAS;
  293. uint8_t Reserved4 [5];
  294. struct station stations [1];
  295. }
  296. * network;
  297. struct __packed networks
  298. {
  299. uint8_t Reserved;
  300. uint8_t NUMAVLNS;
  301. struct network networks [1];
  302. }
  303. * networks = (struct networks *) (confirm-&gt;DATA);
  304. #else
  305. #error &quot;Unspecified Atheros chipset&quot;
  306. #endif
  307. struct plcnetwork * plcnetwork = (struct plcnetwork *)(&amp;plctopology-&gt;plcnetwork);
  308. struct plcstation * plcstation;
  309. byte bridges [255] [ETHER_ADDR_LEN];
  310. unsigned bridge = LocalDevices (channel, message, bridges, (size_t)(sizeof (bridges)));
  311. while (bridge--)
  312. {
  313. memset (message, 0, sizeof (* message));
  314. memcpy (channel-&gt;peer, bridges [bridge], sizeof (channel-&gt;peer));
  315. #if defined (INT6x00)
  316. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  317. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_NW_INFO | MMTYPE_REQ));
  318. #elif defined (AR7x00)
  319. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  320. QualcommHeader1 (&amp;request-&gt;qualcomm, 1, (VS_NW_INFO | MMTYPE_REQ));
  321. #else
  322. #error &quot;Unspecified Atheros chipset&quot;
  323. #endif
  324. if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) &lt;= 0)
  325. {
  326. error (1, errno, CHANNEL_CANTSEND);
  327. }
  328. while ((packetsize = readpacket (channel, message, sizeof (* message))) &gt; 0)
  329. {
  330. #if defined (INT6x00)
  331. if (UnwantedMessage (confirm, packetsize, 0, (VS_NW_INFO | MMTYPE_CNF)))
  332. #elif defined (AR7x00)
  333. if (UnwantedMessage (confirm, packetsize, 1, (VS_NW_INFO | MMTYPE_CNF)))
  334. #else
  335. #error &quot;Unspecified Atheros chipset&quot;
  336. #endif
  337. {
  338. continue;
  339. }
  340. network = (struct network *)(&amp;networks-&gt;networks);
  341. plcstation = (struct plcstation *)(&amp;plcnetwork-&gt;plcstation);
  342. memset (plcnetwork, 0, sizeof (* plcnetwork));
  343. memset (plcstation, 0, sizeof (* plcstation));
  344. plcstation-&gt;LOC = !memcmp (confirm-&gt;ethernet.OSA, bridges [bridge], sizeof (confirm-&gt;ethernet.OSA));
  345. plcstation-&gt;CCO = !memcmp (confirm-&gt;ethernet.OSA, network-&gt;CCO_MAC, sizeof (confirm-&gt;ethernet.OSA));
  346. plcstation-&gt;TEI = network-&gt;TEI;
  347. memcpy (plcstation-&gt;MAC, confirm-&gt;ethernet.OSA, sizeof (plcstation-&gt;MAC));
  348. memcpy (plcstation-&gt;BDA, confirm-&gt;ethernet.ODA, sizeof (plcstation-&gt;BDA));
  349. PLCPlatform (channel, plcstation);
  350. plcnetwork-&gt;plcstations++;
  351. plcstation++;
  352. while (networks-&gt;NUMAVLNS--)
  353. {
  354. station = (struct station *)(&amp;network-&gt;stations);
  355. while (network-&gt;NUMSTAS--)
  356. {
  357. memset (plcstation, 0, sizeof (* plcstation));
  358. plcstation-&gt;LOC = !memcmp (station-&gt;BDA, channel-&gt;host, sizeof (station-&gt;BDA));
  359. plcstation-&gt;CCO = !memcmp (station-&gt;MAC, network-&gt;CCO_MAC, sizeof (station-&gt;MAC));
  360. plcstation-&gt;TEI = station-&gt;TEI;
  361. memcpy (plcstation-&gt;MAC, station-&gt;MAC, sizeof (plcstation-&gt;MAC));
  362. memcpy (plcstation-&gt;BDA, station-&gt;BDA, sizeof (plcstation-&gt;BDA));
  363. #if defined (INT6x00)
  364. plcstation-&gt;TX = station-&gt;AVGTX;
  365. plcstation-&gt;RX = station-&gt;AVGRX;
  366. #elif defined (AR7x00)
  367. plcstation-&gt;TX = LE16TOH (station-&gt;AVGTX);
  368. plcstation-&gt;RX = LE16TOH (station-&gt;AVGRX);
  369. #else
  370. #error &quot;Unspecified Atheros chipset&quot;
  371. #endif
  372. PLCPlatform (channel, plcstation);
  373. PLCIdentity (channel, plcstation);
  374. plcnetwork-&gt;plcstations++;
  375. plcstation++;
  376. station++;
  377. }
  378. plctopology-&gt;plcnetworks++;
  379. plcnetwork = (struct plcnetwork *)(plcstation);
  380. network = (struct network *)(station);
  381. }
  382. }
  383. }
  384. return (0);
  385. }
  386. /*====================================================================*
  387. *
  388. *--------------------------------------------------------------------*/
  389. #endif
  390. </pre>
  391. <div class='footerlink'>
  392. [<a href='plctool.c.html' title=' plctool.c '>PREV</a>]
  393. [<a href='toolkit.html' title=' Index '>HOME</a>]
  394. [<a href='PLCTopologyPrint.c.html' title=' PLCTopologyPrint.c '>NEXT</a>]
  395. </div>
  396. </body>
  397. </html>