plc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. #ifndef PLC_HEADER
  42. #define PLC_HEADER
  43. /*====================================================================*
  44. * system header files;
  45. *--------------------------------------------------------------------*/
  46. #include <stdint.h>
  47. /*====================================================================*
  48. * custom header files;
  49. *--------------------------------------------------------------------*/
  50. #include "../ether/channel.h"
  51. #include "../key/HPAVKey.h"
  52. #include "../tools/types.h"
  53. #include "../plc/chipset.h"
  54. #include "../mme/mme.h"
  55. #include "../nvm/nvm.h"
  56. #include "../pib/pib.h"
  57. /*====================================================================*
  58. * constants; these codes are returned in the DEVICEID field of the
  59. * firmware VS_SW_VER message;
  60. *--------------------------------------------------------------------*/
  61. #define PLC_MODULE_SOFTLOADER 0x00
  62. #define PLC_MODULE_FIRMWARE (1 << 0)
  63. #define PLC_MODULE_PARAMETERS (1 << 1)
  64. #define PLC_MODULE_NVM_PIB (PLC_MODULE_PARAMETERS | PLC_MODULE_FIRMWARE)
  65. #define PLC_MODULE_OPERATION (1 << 3)
  66. #define PLC_MODULE_UPGRADE (PLC_MODULE_OPERATION | PLC_MODULE_PARAMETERS | PLC_MODULE_FIRMWARE)
  67. #define PLC_MODULE_FORCE_FLASH (1 << 4)
  68. #define PLC_MODULE_DO_NOT_REBOOT (1 << 5)
  69. #define PLC_MODULE_ALTERNATE_SECTION (1 << 6)
  70. #define PLC_MODULE_FORCE_SECTION (1 << 7)
  71. /*====================================================================*
  72. * constants;
  73. *--------------------------------------------------------------------*/
  74. #define PLC_VERSION_STRING 0xFF
  75. #define PLC_RECORD_SIZE 1024
  76. #define PLC_MODULE_SIZE 1400
  77. #define PLC_SLOTS 6
  78. #define LEGACY_PIBOFFSET 0x01F00000
  79. #define INT6x00_PIBOFFSET 0x01000000
  80. #define AR7x00_PIBOFFSET 0x00200000
  81. #define INT_CARRIERS 1155
  82. #define AMP_CARRIERS 2880
  83. #define PLC_CARRIERS 1345
  84. #define AMP_BITS 9
  85. /*====================================================================*
  86. * device manager flagword bits;
  87. *--------------------------------------------------------------------*/
  88. /*
  89. * We reuse flagword bits in various programs to avoid proliferating
  90. * flagwords; make sure that one program does not use multiple names
  91. * ro refer to the same bit;
  92. */
  93. #define PLC_BAILOUT (1 << 0)
  94. #define PLC_SILENCE (1 << 1)
  95. #define PLC_VERBOSE (1 << 2)
  96. #define PLC_ANALYSE (1 << 3)
  97. #define PLC_ERASE_DEVICE PLC_ANALYSE /* ampinit, plcinit */
  98. #define PLC_NEWLINE PLC_ANALYSE /* ampID, plcID */
  99. #define PLC_WAITFORRESET (1 << 4)
  100. #define PLC_WAITFORSTART (1 << 5)
  101. #define PLC_WAITFORASSOC (1 << 6)
  102. #define PLC_REMOTEHOSTS PLC_WAITFORASSOC
  103. #define PLC_RESET_DEVICE (1 << 7)
  104. #define PLC_RANDOM_ADDR PLC_RESET_DEVICE
  105. #define PLC_TIM_GARGRAVE PLC_RESET_DEVICE
  106. #define PLC_BRIDGE_LIST PLC_RESET_DEVICE /* plclist, amplist */
  107. #define PLC_FACTORY_DEFAULTS (1 << 8)
  108. #define PLC_FOREVER PLC_FACTORY_DEFAULTS /* plctest */
  109. #define PLC_GRAPH PLC_FACTORY_DEFAULTS /* plctone */
  110. #define PLC_DAEMON PLC_FACTORY_DEFAULTS /* plchost */
  111. #define PLC_REMOTE_LIST PLC_FACTORY_DEFAULTS /* plclist, amplist */
  112. #define PLC_BINARY PLC_FACTORY_DEFAULTS /* ampsnif */
  113. #define PLC_FORCE_FLASH PLC_FACTORY_DEFAULTS /* plchost */
  114. #define PLC_NETWORK (1 << 9)
  115. #define PLC_OPEN_SESSION PLC_NETWORK /* plcmod */
  116. #define PLC_MONITOR PLC_NETWORK /* ampsnif */
  117. #define PLC_XML_FORMAT PLC_NETWORK /* int6klog */
  118. #define PLC_VERSION (1 << 10)
  119. #define PLC_WRITE_MODULE PLC_VERSION /* plcmod */
  120. #define PLC_MANUFACTURER (1 << 11)
  121. #define PLC_READ_MODULE PLC_MANUFACTURER /* plcmod */
  122. #define PLC_READ_MAC (1 << 12)
  123. #define PLC_DUMP_MODULE PLC_READ_MAC /* int6mod */
  124. #define PLC_LOCAL_TRAFFIC PLC_READ_MAC /* int6krate, amprate, plcrate */
  125. #define PLC_READ_PIB (1 << 13)
  126. #define PLC_NETWORK_TRAFFIC PLC_READ_PIB /* plcrate */
  127. #define PLC_READ_IDENTITY (1 << 14)
  128. #define PLC_UNCODED_RATES PLC_READ_IDENTITY /* plcrate */
  129. #define PLC_WRITE_MAC (1 << 15)
  130. #define PLC_LINK_STATS PLC_WRITE_MAC /* plcstat */
  131. #define PLC_WRITE_PIB (1 << 16)
  132. #define PLC_TONE_MAP PLC_WRITE_PIB /* plcstat */
  133. #define PLC_FLASH_DEVICE (1 << 17)
  134. #define PLC_COMMIT_MODULE PLC_FLASH_DEVICE /* plcmod */
  135. #define PLC_QUICK_FLASH (1 << 18)
  136. #define PLC_SETLOCALKEY (1 << 19)
  137. #define PLC_RXONLY PLC_SETLOCALKEY
  138. #define PLC_SETREMOTEKEY (1 << 20)
  139. #define PLC_TXONLY PLC_SETREMOTEKEY
  140. #define PLC_SDRAM_INFO (1 << 21)
  141. #define PLC_SDRAM_CONFIG (1 << 22)
  142. #define PLC_CONFIGURE PLC_SDRAM_CONFIG /* plcotst */
  143. #define PLC_NVRAM_INFO (1 << 23)
  144. #define PLC_ATTRIBUTES (1 << 24)
  145. #define PLC_PUSH_BUTTON (1 << 25)
  146. #define PLC_READ_CFG (1 << 26)
  147. #define PLC_ERASE_SECTOR PLC_READ_CFG
  148. #define PLC_RD_MOD_WR_PIB (1 << 27)
  149. #define PLC_SNIFFER PLC_RD_MOD_WR_PIB /* ampsnif */
  150. #define PLC_READ_ALL PLC_RD_MOD_WR_PIB /* ampinit */
  151. #define PLC_WATCHDOG_REPORT (1 << 28)
  152. #define PLC_RESULTS PLC_WATCHDOG_REPORT /* plcotst */
  153. #define PLC_HOST_ACTION (1 << 29)
  154. #define PLC_LINK_STATUS PLC_HOST_ACTION
  155. #define PLC_MULTICAST_INFO (1 << 30)
  156. #define PLC_RX_TONEMAPS PLC_HOST_ACTION /* plcstat */
  157. /*====================================================================*
  158. * message format strings;
  159. *--------------------------------------------------------------------*/
  160. #define PLC_BADVALUE "Invalid or suspect data"
  161. #define PLC_WONTDOIT "Device refused request"
  162. #define PLC_NODEVICE "Need a device. Try 'local' or '00:B0:52:00:00:01'."
  163. #define PLC_BADFRAME "Unexpected response"
  164. #define PLC_NODETECT "Device must be connected"
  165. #define PLC_NOMEMORY "Not enough memory"
  166. #define PLC_NOTREADY "Function not implemented"
  167. #define PLC_ERR_OFFSET "Data offset error"
  168. #define PLC_ERR_LENGTH "Data length error"
  169. #define PLC_BAD_MAC "Have '%s' instead of MAC address"
  170. #define PLC_BAD_DAK "Have '%s' instead of DAK"
  171. #define PLC_BAD_NMK "Have '%s' instead of NMK"
  172. #define PLC_EXIT(plc) ((signed) (plc->flags & PLC_BAILOUT))
  173. /*====================================================================*
  174. * program constants;
  175. *--------------------------------------------------------------------*/
  176. #define PLCDEVICE "PLC"
  177. #define HARDWAREID 0
  178. #define SOFTWAREID 0
  179. #define PLCSESSION 0x78563412
  180. #define HOSTACTION 0
  181. #define SECTORCODE 0
  182. #define PUSHBUTTON 1
  183. #define MODULECODE (VS_MODULE_MAC | VS_MODULE_PIB)
  184. #define READACTION 0
  185. #define FLASH_SIZE 0x200000
  186. #define PLCOUPLING 0
  187. #define PLC_STATE 0
  188. #define PLC_TIMER 60
  189. #define PLC_SLEEP 0
  190. #define PLC_COUNT 1
  191. #define PLC_INDEX 0
  192. #define PLC_FLAGS 0
  193. #define PLC_MEMTYPE_AUTO 1
  194. #define PLC_MEMTYPE_ITCM 2
  195. #define PLC_MEMTYPE_DTCM 3
  196. #define PLC_MEMTYPE_SRAM 4
  197. #define PLC_MEMTYPE_SDRAM 5
  198. #define PLC_ECHOTIME 3
  199. #define PLC_LONGTIME (unsigned)(~0)
  200. /*====================================================================*
  201. * common mac address names;
  202. *--------------------------------------------------------------------*/
  203. #define PLCDEVICES 3
  204. extern struct _term_ const devices [PLCDEVICES];
  205. /*====================================================================*
  206. *
  207. * the plc structure holds everything needed to perform powerline
  208. * device management operations including a channel structure for
  209. * Ethernet interface management and a message structure for data
  210. * buffer management;
  211. *
  212. * the channel structure holds information needed to open, read,
  213. * write and close a raw socket; it differs in detail depending
  214. * on constants WINPCAP and LIBPCAP;
  215. *
  216. * character array address[] holds a decoded ethernet address for
  217. * display purposes because humans cannot read;
  218. *
  219. * byte array LMA[] holds the Qualcomm Local Broadcast Address
  220. * because it is used in so many places;
  221. *
  222. * byte arrays NMK[] and DAK[] hold encryption keys used by some
  223. * operations;
  224. *
  225. * the socket _file_ structure holds the descriptor and interface
  226. * name of the host NIC where the name is eth0, eth1, ... or ethn;
  227. *
  228. * the three _file_ structures, CFG, NVM, and PIB hold descriptors
  229. * and filenames for files written to the device;
  230. *
  231. * the three _file_ structures cfg, nvm and pib hold
  232. * descriptors and filenames of files read from the device;
  233. *
  234. * integers retry and timer are used by program plcwait;
  235. *
  236. * integers index, count and pause control command line looping
  237. * and waiting;
  238. *
  239. * flag_t flags contains bits that define program operations and
  240. * control utility program flow;
  241. *
  242. *--------------------------------------------------------------------*/
  243. typedef struct plc
  244. {
  245. struct channel * channel;
  246. struct message * message;
  247. void * content;
  248. ssize_t packetsize;
  249. uint8_t MAC [ETHER_ADDR_LEN];
  250. uint8_t RDA [ETHER_ADDR_LEN];
  251. uint8_t NMK [HPAVKEY_NMK_LEN];
  252. uint8_t DAK [HPAVKEY_DAK_LEN];
  253. struct _file_ CFG;
  254. struct _file_ cfg;
  255. struct _file_ SFT;
  256. struct _file_ sft;
  257. struct _file_ NVM;
  258. struct _file_ nvm;
  259. struct _file_ PIB;
  260. struct _file_ pib;
  261. struct _file_ XML;
  262. struct _file_ rpt;
  263. struct _file_ socket;
  264. uint32_t hardwareID;
  265. uint32_t softwareID;
  266. uint32_t cookie;
  267. uint8_t action;
  268. uint8_t sector;
  269. uint8_t module;
  270. uint8_t pushbutton;
  271. uint8_t readaction;
  272. uint8_t coupling;
  273. unsigned flash_size;
  274. unsigned state;
  275. unsigned timer;
  276. unsigned sleep;
  277. unsigned count;
  278. unsigned index;
  279. flag_t flags;
  280. flag_t flag2;
  281. }
  282. PLC;
  283. /*====================================================================*
  284. * fixer-upper functions that compensate for errors and omissions;
  285. *--------------------------------------------------------------------*/
  286. void chipset (void const * memory);
  287. char const * chipsetname (uint8_t chipset);
  288. /*====================================================================*
  289. * functions;
  290. *--------------------------------------------------------------------*/
  291. signed Attributes (struct plc *);
  292. signed Attributes1 (struct plc *);
  293. signed Attributes2 (struct plc *);
  294. signed BootDevice (struct plc *);
  295. signed BootDevice1 (struct plc *);
  296. signed BootDevice2 (struct plc *);
  297. signed BootDeviceFirmware (struct plc *);
  298. signed BootDeviceParameters (struct plc *);
  299. signed BootFirmware1 (struct plc *);
  300. signed BootFirmware2 (struct plc *);
  301. signed BootParameters1 (struct plc *);
  302. signed BootParameters2 (struct plc *);
  303. signed ChangeIdent (struct plc *);
  304. signed CrossTraffic (struct plc *);
  305. signed CrossTrafficOne (struct plc *);
  306. signed CrossTrafficTwo (struct plc *);
  307. signed DeviceIdent (struct plc *);
  308. signed EmulateHost (struct plc *);
  309. signed EmulateHost64 (struct plc *);
  310. signed EraseFlashSector (struct plc *);
  311. signed ExecuteApplets (struct plc *);
  312. signed ExecuteApplets1 (struct plc *);
  313. signed ExecuteApplets2 (struct plc *);
  314. signed FactoryDefaults (struct plc *);
  315. signed FactoryReset (struct plc *);
  316. signed FlashNVM (struct plc *);
  317. signed FlashPTS (struct plc *);
  318. signed FlashDevice (struct plc *);
  319. signed FlashDevice0 (struct plc *);
  320. signed FlashDevice1 (struct plc *);
  321. signed FlashDevice2 (struct plc *, uint32_t options);
  322. signed FlashFirmware (struct plc *, uint32_t options);
  323. signed FlashParameters (struct plc *, uint32_t options);
  324. signed FlashUpgrade (struct plc *, uint32_t options);
  325. signed FlashNVM (struct plc *);
  326. signed FlashSoftloader (struct plc *, uint32_t options);
  327. signed HostActionResponse (struct plc *);
  328. signed Identity (struct plc *);
  329. signed Identity1 (struct plc *);
  330. signed Identity2 (struct plc *);
  331. signed InitDevice (struct plc *);
  332. signed InitDevice1 (struct plc *);
  333. signed InitDevice2 (struct plc *);
  334. signed LinkStatistics (struct plc *);
  335. signed LinkStatus (struct plc *);
  336. signed ListLocalDevices (struct plc * plc, char const * space, char const * comma);
  337. signed LocalTrafficSend (struct plc * plc);
  338. signed Antiphon (struct plc * plc, uint8_t osa [], uint8_t oda []);
  339. signed MDUTrafficStats (struct plc *, uint8_t command, uint8_t session, uint8_t slave);
  340. signed MfgString (struct plc *);
  341. signed MulticastInfo1 (struct plc *);
  342. signed MulticastInfo2 (struct plc *);
  343. signed NVMSelect (struct plc *, signed (struct plc *), signed (struct plc *));
  344. signed NVRAMInfo (struct plc *);
  345. signed NetInfo (struct plc *);
  346. signed NetInfo1 (struct plc *);
  347. signed NetInfo2 (struct plc *);
  348. signed NetworkDevices (struct plc *, void * memory, size_t extent);
  349. signed NetworkDevices1 (struct plc *, void * memory, size_t extent);
  350. signed NetworkDevices2 (struct plc *, void * memory, size_t extent);
  351. signed NetworkInfoStats (struct plc *);
  352. signed NetworkInformation (struct plc *);
  353. signed NetworkInformation1 (struct plc *);
  354. signed NetworkInformation2 (struct plc *);
  355. signed NetworkProbe (struct plc *);
  356. signed NetworkTraffic (struct plc *);
  357. signed NetworkTraffic1 (struct plc *);
  358. signed NetworkTraffic2 (struct plc *);
  359. signed PLCSelect (struct plc *, signed method1 (struct plc *), signed method2 (struct plc *));
  360. signed PhyRates (struct plc *);
  361. signed PhyRates1 (struct plc *);
  362. signed PhyRates2 (struct plc *);
  363. signed RxRates2 (struct plc *);
  364. signed TxRates2 (struct plc *);
  365. signed PushButton (struct plc *);
  366. signed ReadFMI (struct plc *, uint8_t MMV, uint16_t MMTYPE);
  367. signed ReadMFG (struct plc *, uint8_t MMV, uint16_t MMTYPE);
  368. signed ReadMME (struct plc *, uint8_t MMV, uint16_t MMTYPE);
  369. signed ReadFirmware (struct plc *);
  370. signed ReadFirmware1 (struct plc *);
  371. signed ReadFirmware2 (struct plc *);
  372. signed ReadParameterBlock (struct plc *, void * memory, size_t extent);
  373. signed ReadParameters (struct plc *);
  374. signed ReadParameters1 (struct plc *);
  375. signed ReadParameters2 (struct plc *);
  376. signed ListRemoteDevices (struct plc *, char const * space, char const * comma);
  377. signed ListRemoteDevices1 (struct plc *, char const * space, char const * comma);
  378. signed ListRemoteDevices2 (struct plc *, char const * space, char const * comma);
  379. signed RemoteHosts (struct plc *);
  380. signed Reset (struct plc *);
  381. signed ResetAndWait (struct plc *);
  382. signed ResetDevice (struct plc *);
  383. signed SDRAMInfo (struct plc *);
  384. signed SendMME (struct plc *);
  385. signed SetNMK (struct plc *);
  386. signed SignalToNoise1 (struct plc *);
  387. signed SignalToNoise2 (struct plc *);
  388. signed SlaveMembership (struct plc *);
  389. signed StartDevice (struct plc *);
  390. signed StartDevice1 (struct plc *);
  391. signed StartDevice2 (struct plc *);
  392. signed StartFirmware (struct plc *, unsigned module, void const * header);
  393. signed StartFirmware1 (struct plc *, unsigned module, const struct nvm_header1 *);
  394. signed StartFirmware2 (struct plc *, unsigned module, const struct nvm_header2 *);
  395. signed ToneMaps1 (struct plc *);
  396. signed ToneMaps2 (struct plc *);
  397. signed Topology (struct plc *);
  398. signed Topology1 (struct plc *);
  399. signed Topology2 (struct plc *);
  400. signed Traffic (struct plc *);
  401. signed Traffic1 (struct plc *);
  402. signed Traffic2 (struct plc *);
  403. signed Traffic3 (struct plc *);
  404. signed Transmit (struct plc *, uint8_t osa [], uint8_t oda []);
  405. signed UpgradeDevice1 (struct plc *);
  406. signed MDUTrafficStats (struct plc *, uint8_t command, uint8_t session, uint8_t slave);
  407. signed VersionInfo (struct plc *);
  408. signed VersionInfo1 (struct plc *);
  409. signed VersionInfo2 (struct plc *);
  410. signed WaitForAssoc (struct plc *);
  411. signed WaitForAssoc1 (struct plc *);
  412. signed WaitForAssoc2 (struct plc *);
  413. signed WaitForBootLoader (struct plc *);
  414. signed WaitForReset (struct plc *);
  415. signed WaitForRestart (struct plc *);
  416. signed WaitForStart (struct plc *, char buffer [], size_t length);
  417. signed WatchdogReport (struct plc *);
  418. signed WriteCFG (struct plc *);
  419. signed WriteExecuteApplet2 (struct plc *, unsigned module, const struct nvm_header2 *);
  420. signed WriteExecuteFirmware (struct plc *, unsigned module, void const * nvm_header);
  421. signed WriteExecuteFirmware1 (struct plc *, unsigned module, const struct nvm_header1 *);
  422. signed WriteExecuteFirmware2 (struct plc *, unsigned module, const struct nvm_header2 *);
  423. signed WriteExecuteParameters (struct plc *, unsigned module, void const * nvm_header);
  424. signed WriteExecuteParameters1 (struct plc *, unsigned module, const struct nvm_header1 *);
  425. signed WriteExecuteParameters2 (struct plc *, unsigned module, const struct nvm_header2 *);
  426. signed WriteExecutePIB (struct plc *, unsigned offset, struct pib_header *);
  427. signed WriteFirmware (struct plc *, unsigned module, void const * nvm_header);
  428. signed WriteFirmware1 (struct plc *, unsigned module, const struct nvm_header1 *);
  429. signed WriteFirmware2 (struct plc *, unsigned module, const struct nvm_header2 *);
  430. signed WriteMEM (struct plc *, struct _file_ *, unsigned module, uint32_t offset, uint32_t extent);
  431. signed WriteMOD (struct plc *, uint8_t module, void const * memory, size_t extent);
  432. signed WriteNVM (struct plc *);
  433. signed WritePIB (struct plc *);
  434. signed WriteParameters (struct plc *, unsigned module, void const * nvm_header);
  435. signed WriteParameters1 (struct plc *, unsigned module, const struct nvm_header1 *);
  436. signed WriteParameters2 (struct plc *, unsigned module, const struct nvm_header2 *);
  437. /*====================================================================*
  438. *
  439. *--------------------------------------------------------------------*/
  440. #define PLC_FORMAT_HEX 0
  441. #define PLC_FORMAT_DEC 1
  442. #define PLC_FORMAT_BIN 2
  443. #define PLC_FORMAT_ASC 3
  444. #ifndef __GNUC__
  445. #pragma pack (push,1)
  446. #endif
  447. struct __packed plcproperty
  448. {
  449. uint8_t PROP_OPTION;
  450. uint8_t PROP_FORMAT;
  451. uint32_t PROP_NUMBER;
  452. uint32_t PROP_VERSION;
  453. uint32_t PROP_LENGTH;
  454. uint8_t PROP_BUFFER [128];
  455. uint8_t DATA_FORMAT;
  456. uint32_t DATA_LENGTH;
  457. uint8_t DATA_BUFFER [128];
  458. }
  459. plcproperty;
  460. #ifndef __GNUC__
  461. #pragma pack (pop)
  462. #endif
  463. /*====================================================================*
  464. *
  465. *--------------------------------------------------------------------*/
  466. signed GetProperty (struct plc *, struct plcproperty *);
  467. signed SetProperty (struct plc *, struct plcproperty *);
  468. /*====================================================================*
  469. *
  470. *--------------------------------------------------------------------*/
  471. typedef struct __packed plcstation
  472. {
  473. uint8_t LOC;
  474. uint8_t CCO;
  475. uint8_t TEI;
  476. uint8_t MAC [ETHER_ADDR_LEN];
  477. uint8_t BDA [ETHER_ADDR_LEN];
  478. uint16_t TX;
  479. uint16_t RX;
  480. char hardware [0x10];
  481. char firmware [0x80];
  482. char identity [0x40];
  483. }
  484. plcstation;
  485. typedef struct __packed plcnetwork
  486. {
  487. signed ifname;
  488. signed plcstations;
  489. struct plcstation plcstation [1];
  490. }
  491. plcnetwork;
  492. typedef struct __packed plctopology
  493. {
  494. signed plcnetworks;
  495. struct plcnetwork plcnetwork [1];
  496. }
  497. pcltopology;
  498. /*====================================================================*
  499. * functions that use struct channel and struct message directly
  500. * instead of struct plc;
  501. *--------------------------------------------------------------------*/
  502. signed FlashMOD (struct channel *, uint8_t module);
  503. signed WriteModule (struct channel *, struct message *, void const * memory, size_t extent);
  504. signed WriteMemory (struct channel *, struct message *, struct _file_ *, uint32_t offset, uint32_t extent);
  505. unsigned LocalDevices (struct channel const *, struct message *, void * memory, size_t extent);
  506. signed Platform (struct channel *, const byte device []);
  507. signed PLCReadParameterBlock (struct channel *, struct message *, void * memory, size_t extent);
  508. signed PLCReadFirmwareImage (struct channel *, struct message *, void * memory, size_t extent);
  509. signed PLCTopology (struct channel *, struct message *, struct plctopology *);
  510. signed PLCTopologyPrint (struct plctopology *);
  511. /*====================================================================*
  512. * vs_module_spec message;
  513. *--------------------------------------------------------------------*/
  514. #define PLC_MODULE_EXECUTE (1 << 0)
  515. #define PLC_MODULE_ABSOLUTE (1 << 1)
  516. #define PLC_MODULE_RELATIVE (0 << 1)
  517. #define PLC_MODULE_READ_TIMEOUT 5000
  518. #define PLC_MODULE_REQUEST_TIMEOUT 60000
  519. #define PLC_MODULE_WRITE_TIMEOUT 90000
  520. #define PLC_MOD_OP_READ_MEMORY 0x00
  521. #define PLC_MOD_OP_READ_FLASH 0x01
  522. #define PLC_MOD_OP_START_SESSION 0x10
  523. #define PLC_MOD_OP_WRITE_MODULE 0x11
  524. #define PLC_MOD_OP_CLOSE_SESSION 0x12
  525. #define PLC_MODULEID 0x0000
  526. #define PLC_SUBMODULEID 0x0000
  527. #define PLC_MODULEID_MDIO_INIT 0x1000
  528. #define PLC_MODULEID_UART_ASYNC 0x2000
  529. #define PLC_MODULEID_ADDR_ENUM 0x3000
  530. #define PLC_MODULEID_POWER_MGT 0x4000
  531. #define PLC_MODULEID_TR069 0x4001
  532. #define PLC_MODULEID_FORWARDCFG 0x7000
  533. #define PLC_MODULEID_FIRMWARE 0x7001
  534. #define PLC_MODULEID_PARAMETERS 0x7002
  535. #define PLC_MODULEID_SOFTLOADER 0x7003
  536. #define PLC_MODULEID_RESERVED1 0x7004
  537. #define PLC_MODULEID_PIBMERGE 0x7005
  538. #define PLC_MODULEID_RESERVED2 0x7006
  539. typedef struct __packed vs_module_spec
  540. {
  541. uint16_t MODULE_ID;
  542. uint16_t MODULE_SUB_ID;
  543. uint32_t MODULE_LENGTH;
  544. uint32_t MODULE_CHKSUM;
  545. }
  546. vs_module_spec;
  547. #define PLC_COMMIT_FORCE (1 << 0)
  548. #define PLC_COMMIT_NORESET (1 << 1)
  549. #define PLC_COMMIT_FACTPIB (1 << 31)
  550. /*====================================================================*
  551. * functions;
  552. *--------------------------------------------------------------------*/
  553. signed ModuleSpec (struct _file_ *, struct vs_module_spec *);
  554. signed ModuleSession (struct plc *, unsigned modules, vs_module_spec *);
  555. signed ModuleWrite (struct plc *, struct _file_ *, unsigned module, vs_module_spec *);
  556. signed ModuleRead (struct plc *, struct _file_ *, uint16_t source, uint16_t module, uint16_t submodule);
  557. signed ModuleDump (struct plc *, uint16_t source, uint16_t module, uint16_t submodule);
  558. signed ModuleCommit (struct plc *, uint32_t flags);
  559. /*====================================================================*
  560. * functions;
  561. *--------------------------------------------------------------------*/
  562. #ifdef __GNUC__
  563. __attribute__ ((format (printf, 2, 3)))
  564. #endif
  565. void Request (struct plc *, char const * format, ...);
  566. #ifdef __GNUC__
  567. __attribute__ ((format (printf, 2, 3)))
  568. #endif
  569. void Confirm (struct plc *, char const * format, ...);
  570. #ifdef __GNUC__
  571. __attribute__ ((format (printf, 2, 3)))
  572. #endif
  573. void Display (struct plc *, char const * format, ...);
  574. #ifdef __GNUC__
  575. __attribute__ ((format (printf, 2, 3)))
  576. #endif
  577. void Failure (struct plc *, char const * format, ...);
  578. /*====================================================================*
  579. *
  580. *--------------------------------------------------------------------*/
  581. #endif