/*====================================================================* * * Copyright (c) 2013 Qualcomm Atheros, Inc. * * All rights reserved. * *====================================================================*/ /*====================================================================* * * signed Identity1 (struct plc * plc); * * plc.h * * Read the first block of the PIB image from a powerline device * using VA_RD_MOD; print identity information on stdout; * * Contributor(s): * Charles Maier * *--------------------------------------------------------------------*/ #ifndef IDENTITY1_SOURCE #define IDENTITY1_SOURCE #include #include "../plc/plc.h" #include "../tools/error.h" #include "../tools/memory.h" #include "../pib/pib.h" signed Identity1 (struct plc * plc) { struct channel * channel = (struct channel *) (plc->channel); struct message * message = (struct message *) (plc->message); #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_rd_mod_request { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t MODULEID; uint8_t MACCESS; uint16_t MLENGTH; uint32_t MOFFSET; uint8_t MSECRET [16]; } * request = (struct vs_rd_mod_request *) (message); struct __packed vs_rd_mod_confirm { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t MSTATUS; uint8_t RES [3]; uint8_t MODULEID; uint8_t RESERVED; uint16_t MLENGTH; uint32_t MOFFSET; uint32_t MCHKSUM; uint8_t BUFFER [PLC_RECORD_SIZE]; } * confirm = (struct vs_rd_mod_confirm *) (message); #ifndef __GNUC__ #pragma pack (pop) #endif Request (plc, "Device Identity"); memset (message, 0, sizeof (* message)); EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (& request->qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ)); plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN); request->MODULEID = VS_MODULE_PIB; request->MLENGTH = HTOLE16 (sizeof (confirm->BUFFER)); request->MOFFSET = HTOLE32 (0); if (SendMME (plc) <= 0) { error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND); return (-1); } while (ReadMME (plc, 0, (VS_RD_MOD | MMTYPE_CNF)) > 0) { if (confirm->MSTATUS) { Failure (plc, PLC_WONTDOIT); continue; } Confirm (plc, "-------"); lightning_pib_peek (confirm->BUFFER); } return (0); } #endif