signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE) { struct channel * channel = (struct channel *)(plc->channel); struct message * message = (struct message *)(plc->message); struct timeval ts; struct timeval tc; if (gettimeofday (&ts, NULL) == -1) { error (1, errno, CANT_START_TIMER); } while ((plc->packetsize = readpacket (channel, message, sizeof (* message))) >= 0) { if (UnwantedMessage (message, plc->packetsize, MMV, MMTYPE)) { if (gettimeofday (&tc, NULL) == -1) { error (1, errno, CANT_RESET_TIMER); } if (channel->timeout < 0) { continue; } if (channel->timeout > MILLISECONDS (ts, tc)) { continue; } plc->packetsize = 0; } break; } return (plc->packetsize); }
static void function (struct channel * channel, void * memory, ssize_t extent) { struct ether_header * frame = (struct ether_header *)(memory); unsigned length; while ((length = (unsigned)(hexload (memory, extent, stdin))) > 0) { if (length < (ETHER_MIN_LEN - ETHER_CRC_LEN)) { error (1, ENOTSUP, "Frame size of %d is less than %d bytes", length, (ETHER_MIN_LEN - ETHER_CRC_LEN)); } if (length > (ETHER_MAX_LEN - ETHER_CRC_LEN)) { error (1, ENOTSUP, "Frame size of %d is more than %d bytes", length, (ETHER_MAX_LEN - ETHER_CRC_LEN)); } if (_anyset (channel->flags, CHANNEL_UPDATE_TARGET)) { memcpy (frame->ether_dhost, channel->peer, sizeof (frame->ether_dhost)); } if (_anyset (channel->flags, CHANNEL_UPDATE_SOURCE)) { memcpy (frame->ether_shost, channel->host, sizeof (frame->ether_shost)); } sendpacket (channel, memory, length); if (_anyset (channel->flags, CHANNEL_LISTEN)) { while (readpacket (channel, memory, extent) > 0); } } return; }
int NCD4_readDMR(NCD4INFO* state) { int stat = NC_NOERR; long lastmodified = -1; stat = readpacket(state,state->uri,state->curl->packet,NCD4_DMR,&lastmodified); if(stat == NC_NOERR) state->data.dmrlastmodified = lastmodified; return THROW(stat); }
int readDDS(OCstate* state, OCtree* tree) { int status; long lastmodified = -1; dapurlsetconstraints(&state->url,tree->constraint); status = readpacket(state->curl,&state->url,state->packet,OCDDS, &lastmodified); if(status == OC_NOERR) state->ddslastmodified = lastmodified; return status; }
int readDAS(OCstate* state, OCtree* tree) { int stat = OC_NOERR; ocurisetconstraints(state->uri,tree->constraint); #ifdef OCDEBUG fprintf(stderr,"readDAS:\n"); #endif stat = readpacket(state,state->uri,state->packet,OCDAS,NULL); return stat; }
void serial_reader_f(void) { int main_pid = 0; int bytes; msg_t m; border_packet_t *uart_buf; posix_open(uart0_handler_pid, 0); msg_receive(&m); main_pid = m.sender_pid; while(1) { posix_open(uart0_handler_pid, 0); bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE); if(bytes < 0) { switch(bytes) { case(-SIXLOWERROR_ARRAYFULL): { printf("ERROR: Array was full\n"); break; } default: { printf("ERROR: unknown\n"); break; } } continue; } uart_buf = (border_packet_t *)get_serial_in_buffer(0); if(uart_buf->empty == 0) { if(uart_buf->type == BORDER_PACKET_CONF_TYPE) { border_conf_header_t *conf_packet = (border_conf_header_t *)uart_buf; if(conf_packet->conftype == BORDER_CONF_SYN) { m.content.ptr = (char *)conf_packet; msg_send(&m, main_pid, 1); continue; } } flowcontrol_deliver_from_uart(uart_buf, bytes); } } }
signed Platform (struct channel * channel, const uint8_t device []) { struct message message; ssize_t packetsize; #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_sw_ver_request { struct ethernet_std ethernet; struct qualcomm_std qualcomm; } * request = (struct vs_sw_ver_request *) (&message); struct __packed vs_sw_ver_confirm { struct ethernet_std ethernet; struct qualcomm_std qualcomm; uint8_t MSTATUS; uint8_t MDEVICEID; uint8_t MVERLENGTH; char MVERSION [PLC_VERSION_STRING]; } * confirm = (struct vs_sw_ver_confirm *) (&message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (&message, 0, sizeof (message)); EthernetHeader (&request->ethernet, device, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ)); if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) > 0) { while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0) { if (!UnwantedMessage (&message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF))) { chipset (confirm); printf (" %s", chipsetname (confirm->MDEVICEID)); printf (" %s", confirm->MVERSION); return (0); } } } return (-1); }
signed ListLocalDevices (struct plc * plc, char const * space, char const * comma) { struct channel * channel = (struct channel *)(plc->channel); struct message * message = (struct message *)(plc->message); ssize_t packetsize; #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_sw_ver_request { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; } * request = (struct vs_sw_ver_request *) (message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (message, 0, sizeof (* message)); EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ)); if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0) { return (-1); } while ((packetsize = readpacket (channel, message, sizeof (* message))) > 0) { if (UnwantedMessage (message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF))) { continue; } hexout (request->ethernet.OSA, sizeof (request->ethernet.OSA), HEX_EXTENDER, 0, stdout); if ((space) && (*space)) { printf ("%s", space); } } if ((comma) && (* comma)) { printf ("%s", comma); } return (0); }
int readDDS(OCstate* state, OCtree* tree) { int stat = OC_NOERR; long lastmodified = -1; ocurisetconstraints(state->uri,tree->constraint); #ifdef OCDEBUG fprintf(stderr,"readDDS:\n"); #endif stat = readpacket(state,state->uri,state->packet,OCDDS, &lastmodified); if(stat == OC_NOERR) state->ddslastmodified = lastmodified; return stat; }
const scan_packet* readscan() { if( m_fault ) { COMMA_THROW( comma::exception, "asked to read scan, while having uncleared fault" ); } if( m_commandId ) { COMMA_THROW( comma::exception, "cannot read scan, while waiting for response to 0x" << std::hex << *m_commandId << std::dec ); } if( !readpacket() ) { return NULL; } switch( m_header->type() ) { case header::scan_type: return reinterpret_cast< const scan_packet* >( &m_buf[0] ); case header::fault_type: throw faultException(); // COMMA_THROW( comma::exception, "received fault, while reading scan" ); case header::response_type: COMMA_THROW( comma::exception, "expected scan data, got command response of type 0x" << std::hex << ( reinterpret_cast< const commands::response_header* >( m_payload )->id() & 0x3fff ) << std::dec ); default: COMMA_THROW( comma::exception, "expected scan data, got packet of unknown type (0x" << std::hex << m_header->type() << std::dec ); } }
int readDATADDS(OCstate* state, OCtree* tree, OCflags flags) { int stat = OC_NOERR; long lastmod = -1; #ifdef OCDEBUG fprintf(stderr,"readDATADDS:\n"); #endif if((flags & OCONDISK) == 0) { ocurisetconstraints(state->uri,tree->constraint); stat = readpacket(state,state->uri,state->packet,OCDATADDS,&lastmod); if(stat == OC_NOERR) state->datalastmodified = lastmod; tree->data.datasize = ocbyteslength(state->packet); } else { /*((flags & OCONDISK) != 0) */ OCURI* url = state->uri; int fileprotocol = 0; char* readurl = NULL; fileprotocol = (strcmp(url->protocol,"file")==0); if(fileprotocol && !state->curlflags.proto_file) { readurl = ocuribuild(url,NULL,NULL,0); stat = readfiletofile(readurl, ".dods", tree->data.file, &tree->data.datasize); } else { int flags = 0; if(!fileprotocol) flags |= OCURICONSTRAINTS; flags |= OCURIENCODE; flags |= OCURIUSERPWD; ocurisetconstraints(url,tree->constraint); readurl = ocuribuild(url,NULL,".dods",flags); MEMCHECK(readurl,OC_ENOMEM); if (ocdebug > 0) {fprintf(stderr, "fetch url=%s\n", readurl);fflush(stderr);} stat = ocfetchurl_file(state->curl, readurl, tree->data.file, &tree->data.datasize, &lastmod); if(stat == OC_NOERR) state->datalastmodified = lastmod; if (ocdebug > 0) {fprintf(stderr,"fetch complete\n"); fflush(stderr);} } free(readurl); } return OCTHROW(stat); }
static signed Platform (struct channel * channel, const uint8_t device []) { extern const char * chipset [CHIPSETS+1]; struct message message; #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_sw_ver_confirm { struct header_eth ethernet; struct header_int intellon; uint8_t MSTATUS; uint8_t MDEVICEID; uint8_t MVERLENGTH; char MVERSION [INT6K_VERSTRING]; } * confirm = (struct vs_sw_ver_confirm *) (&message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (&message, 0, sizeof (message)); EthernetHeader (&message.ethernet, device, channel->host); IntellonHeader (&message.intellon, (VS_SW_VER | MMTYPE_REQ)); if (sendpacket (channel, &message, ETHER_MIN_LEN) <= 0) { // error (1, errno, INT6K_CANTSEND); return (0); } if (readpacket (channel, &message, sizeof (message)) <= 0) { // error (1, errno, INT6K_CANTREAD); return (0); } if (confirm->MDEVICEID > CHIPSETS) { confirm->MDEVICEID = 0; } printf (" %s", chipset [confirm->MDEVICEID]); printf (" %s", confirm->MVERSION); return (0); }
signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE) { struct channel * channel = (struct channel *)(plc->channel); struct message * message = (struct message *)(plc->message); while ((plc->packetsize = readpacket (channel, message, sizeof (* message))) > 0) { if (FirmwareMessage (message)) { continue; } if (UnwantedMessage (message, plc->packetsize, MMV, MMTYPE)) { continue; } break; } return (plc->packetsize); }
void *serial_reader_f(void *arg) { unsigned char buf[BUFFER_SIZE]; border_packet_t *packet_buf; while (1) { int n = readpacket(buf, BUFFER_SIZE); if (n > 0) { if (buf[0] == 0) { packet_buf = (border_packet_t *)buf; flowcontrol_deliver_from_tty(packet_buf, n); continue; } printf("\033[00;33m[via serial interface] %s\033[00m\n", buf); } } }
static void function (struct channel * channel, flag_t flags) { struct message message; signed length; while ((length = readpacket (channel, &message, sizeof (message))) >= 0) { if (!length) { continue; } if (_allclr (flags, HPAV_SILENCE)) { MMEPeek (&message, length, stdout); } if (_anyset (flags, HPAV_VERBOSE)) { hexdump (&message, 0, length, stdout); } } return; }
typename command::response readresponse() { while( true ) { if( !readpacket() ) { COMMA_THROW( comma::exception, "expected command response, got end of stream" ); } switch( m_header->type() ) { case header::scan_type: case header::fault_type: // cannot throw yet, since need to get response first break; case header::response_type: { unsigned int id = reinterpret_cast< const commands::response_header* >( m_payload )->id() & 0x3fff; if( int( id ) != *m_commandId ) { COMMA_THROW( comma::exception, "expected response to command 0x" << std::hex << *m_commandId << ", got 0x" << id << std::dec ); } m_commandId.reset(); return *( reinterpret_cast< typename command::response* >( m_payload ) ); } default: COMMA_THROW( comma::exception, "expected command response, got packet of unknown type (0x" << std::hex << m_header->type() << std::dec ); } } }
int readDATADDS(OCstate* state, OCtree* tree) { int stat; long lastmod = -1; #ifndef OC_DISK_STORAGE dapurlsetconstraints(&state->url,tree->constraint); stat = readpacket(state->curl,&state->url,state->packet,OCDATADDS,&lastmod); if(stat == OC_NOERR) state->datalastmodified = lastmod; tree->data.datasize = ocbyteslength(state->packet); #else /*OC_DISK_STORAGE*/ DAPURL* url = &state->url; int fileprotocol = 0; fileprotocol = (strncmp(url->base,"file:",5)==0); if(fileprotocol && !oc_curl_file_supported) { stat = readfiletofile(url->base, ".dods", tree->data.file, &tree->data.datasize); } else { char* fetchurl; dapurlsetconstraints(url,tree->constraint); fetchurl = dapurlgeturl(url,NULL,".dods",!fileprotocol); MEMCHECK(fetchurl,OC_ENOMEM); if (ocdebug > 0) {fprintf(stderr, "fetch url=%s\n", fetchurl);fflush(stderr);} stat = ocfetchurl_file(state->curl, fetchurl, tree->data.file, &tree->data.datasize, &lastmod); if(stat == OC_NOERR) state->datalastmodified = lastmod; if (ocdebug > 0) {fprintf(stderr,"fetch complete\n"); fflush(stderr);} free(fetchurl); } #endif /*OC_DISK_STORAGE*/ return THROW(stat); }
int NCD4_readDAP(NCD4INFO* state, int flags) { int stat = NC_NOERR; long lastmod = -1; if((flags & NCF_ONDISK) == 0) { stat = readpacket(state,state->uri,state->curl->packet,NCD4_DAP,&lastmod); if(stat == NC_NOERR) state->data.daplastmodified = lastmod; } else { /*((flags & NCF_ONDISK) != 0) */ NCURI* url = state->uri; int fileprotocol = (strcmp(url->protocol,"file")==0); if(fileprotocol) { stat = readfiletofile(state, url, ".dap", state->data.ondiskfile, &state->data.datasize); } else { char* readurl = NULL; int flags = 0; if(!fileprotocol) flags |= NCURIQUERY; flags |= NCURIENCODE; flags |= NCURIPWD; #ifdef FIX ncurisetconstraints(url,state->constraint); #endif readurl = ncuribuild(url,NULL,".dods",NCURISVC); if(readurl == NULL) return THROW(NC_ENOMEM); stat = NCD4_fetchurl_file(state->curl, readurl, state->data.ondiskfile, &state->data.datasize, &lastmod); nullfree(readurl); if(stat == NC_NOERR) state->data.daplastmodified = lastmod; } } return THROW(stat); }
unsigned LocalDevices (struct channel const * channel, struct message * message, void * memory, size_t extent) { extern const byte localcast [ETHER_ADDR_LEN]; struct vs_sw_ver_request { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; } * request = (struct vs_sw_ver_request *)(message); uint8_t * origin = (uint8_t *)(memory); uint8_t * offset = (uint8_t *)(memory); ssize_t packetsize; memset (memory, 0, extent); memset (message, 0, sizeof (* message)); EthernetHeader (&request->ethernet, localcast, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ)); if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0) { return (0); } while ((packetsize = readpacket (channel, message, sizeof (* message))) > 0) { if (UnwantedMessage (message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF))) { continue; } if (extent >= sizeof (message->ethernet.OSA)) { memcpy (offset, message->ethernet.OSA, sizeof (message->ethernet.OSA)); offset += sizeof (message->ethernet.OSA); extent -= sizeof (message->ethernet.OSA); } } return ((unsigned)(offset - origin) / ETHER_ADDR_LEN); }
int readversion(CURL* curl, DAPURL* url, OCbytes* packet) { return readpacket(curl,url,packet,OCVER,NULL); }
signed pev_cm_set_key (struct session * session, struct channel * channel, struct message * message) { #ifndef __GNUC__ #pragma pack(push,1) #endif struct __packed cm_set_key_request { struct ethernet_hdr ethernet; struct homeplug_fmi homeplug; uint8_t KEYTYPE; uint32_t MYNOUNCE; uint32_t YOURNOUNCE; uint8_t PID; uint16_t PRN; uint8_t PMN; uint8_t CCOCAP; uint8_t NID [SLAC_NID_LEN]; uint8_t NEWEKS; uint8_t NEWKEY [SLAC_NMK_LEN]; uint8_t RSVD [3]; } * request = (struct cm_set_key_request *) (message); struct __packed cm_set_key_confirm { struct ethernet_hdr ethernet; struct homeplug_fmi homeplug; uint8_t RESULT; uint32_t MYNOUNCE; uint32_t YOURNOUNCE; uint8_t PID; uint16_t PRN; uint8_t PMN; uint8_t CCOCAP; uint8_t RSVD [27]; } * confirm = (struct cm_set_key_confirm *) (message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (message, 0, sizeof (* message)); slac_debug (session, 0, __func__, "--> CM_SET_KEY.REQ"); EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type); HomePlugHeader1 (& request->homeplug, HOMEPLUG_MMV, (CM_SET_KEY | MMTYPE_REQ)); request->KEYTYPE = SLAC_CM_SETKEY_KEYTYPE; memset (& request->MYNOUNCE, 0xAA, sizeof (request->MYNOUNCE)); memset (& request->YOURNOUNCE, 0x00, sizeof (request->YOURNOUNCE)); request->PID = SLAC_CM_SETKEY_PID; request->PRN = HTOLE16 (SLAC_CM_SETKEY_PRN); request->PMN = SLAC_CM_SETKEY_PMN; request->CCOCAP = SLAC_CM_SETKEY_CCO; memcpy (request->NID, session->NID, sizeof (request->NID)); request->NEWEKS = SLAC_CM_SETKEY_EKS; memcpy (request->NEWKEY, session->NMK, sizeof (request->NEWKEY)); #if SLAC_DEBUG if (_anyset (session->flags, SLAC_VERBOSE)) { char string [1024]; slac_debug (session, 0, __func__, "CM_SET_KEY.KEYTYPE %d", request->KEYTYPE); slac_debug (session, 0, __func__, "CM_SET_KEY.MYNOUNCE %s", hexstring (string, sizeof (string), & request->MYNOUNCE, sizeof (request->MYNOUNCE))); slac_debug (session, 0, __func__, "CM_SET_KEY.YOURNOUNCE %s", hexstring (string, sizeof (string), & request->YOURNOUNCE, sizeof (request->MYNOUNCE))); slac_debug (session, 0, __func__, "CM_SET_KEY.PID %d", request->PID); slac_debug (session, 0, __func__, "CM_SET_KEY.PRN %d", LE32TOH (request->PRN)); slac_debug (session, 0, __func__, "CM_SET_KEY.PMN %d", request->PMN); slac_debug (session, 0, __func__, "CM_SET_KEY.CCoCAP %d", request->CCOCAP); slac_debug (session, 0, __func__, "CM_SET_KEY.NID %s", HEXSTRING (string, request->NID)); slac_debug (session, 0, __func__, "CM_SET_KEY.NEWEKS %d", request->NEWEKS); slac_debug (session, 0, __func__, "CM_SET_KEY.NEWKEY %s", HEXSTRING (string, request->NEWKEY)); } #endif if (sendpacket (channel, request, sizeof (* request)) <= 0) { return (slac_debug (session, 1, __func__, CHANNEL_CANTSEND)); } while (readpacket (channel, confirm, sizeof (* confirm)) > 0) { if (ntohs (confirm->ethernet.MTYPE) != ETH_P_HPAV) { slac_debug (session, session->exit, __func__, "Ignore MTYPE 0x%04X", htons (confirm->ethernet.MTYPE)); continue; } if (confirm->homeplug.MMV != HOMEPLUG_MMV) { slac_debug (session, session->exit, __func__, "Ignore MMV 0x%02X", confirm->homeplug.MMV); continue; } if (LE32TOH (confirm->homeplug.MMTYPE) != (CM_SET_KEY | MMTYPE_CNF)) { slac_debug (session, session->exit, __func__, "Ignore MMTYPE 0x%04X", LE32TOH (confirm->homeplug.MMTYPE)); continue; } slac_debug (session, 0, __func__, "<-- CM_SET_KEY.CNF"); if (! confirm->RESULT) { return (slac_debug (session, session->exit, __func__, "Can't set keys")); } #if SLAC_DEBUG if (_anyset (session->flags, SLAC_VERBOSE)) { char string [1024]; slac_debug (session, 0, __func__, "CM_SET_KEY.RESULT %d", confirm->RESULT); slac_debug (session, 0, __func__, "CM_SET_KEY.MYNOUNCE %s", hexstring (string, sizeof (string), & confirm->MYNOUNCE, sizeof (confirm->MYNOUNCE))); slac_debug (session, 0, __func__, "CM_SET_KEY.YOURNOUNCE %s", hexstring (string, sizeof (string), & confirm->YOURNOUNCE, sizeof (confirm->MYNOUNCE))); slac_debug (session, 0, __func__, "CM_SET_KEY.PID %d", confirm->PID); slac_debug (session, 0, __func__, "CM_SET_KEY.PRN %d", LE32TOH (confirm->PRN)); slac_debug (session, 0, __func__, "CM_SET_KEY.PMN %d", confirm->PMN); slac_debug (session, 0, __func__, "CM_SET_KEY.CCoCAP %d", confirm->CCOCAP); } #endif return (0); } return (slac_debug (session, session->exit, __func__, "<-- CM_SET_KEY.CNF ?")); }
int readDAS(OCstate* state, OCtree* tree) { dapurlsetconstraints(&state->url,tree->constraint); return readpacket(state->curl,&state->url,state->packet,OCDAS,NULL); }
signed evse_cm_mnbc_sound (struct session * session, struct channel * channel, struct message * message) { struct timeval ts; struct timeval tc; signed timer = 100 * session->TIME_OUT; unsigned AAG [SLAC_GROUPS]; unsigned sounds = 0; ssize_t length; session->sounds = 0; memset (AAG, 0, sizeof (AAG)); memset (session->AAG, 0, sizeof (session->AAG)); if (gettimeofday (& ts, NULL) == - 1) { slac_debug (session, 1, __func__, CANT_START_TIMER); } while ((length = readpacket (channel, message, sizeof (* message))) >= 0) { struct homeplug * homeplug = (struct homeplug *) (message); if (! length) { } else if (ntohs (homeplug->ethernet.MTYPE) != ETH_P_HPAV) { slac_debug (session, session->exit, __func__, "bad MTYPE"); } else if (homeplug->homeplug.MMV != HOMEPLUG_MMV) { slac_debug (session, session->exit, __func__, "bad MMV"); } else if (LE16TOH (homeplug->homeplug.MMTYPE) == (CM_MNBC_SOUND | MMTYPE_IND)) { struct cm_mnbc_sound_indicate * indicate = (struct cm_mnbc_sound_indicate *) (message); if (! memcmp (session->RunID, indicate->MSVarField.RunID, sizeof (session->RunID))) { slac_debug (session, 0, __func__, "<-- CM_MNBC_SOUND.IND (%d)", sounds); #if SLAC_DEBUG if (_anyset (session->flags, SLAC_VERBOSE)) { char string [256]; slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.APPLICATION_TYPE %d", indicate->APPLICATION_TYPE); slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.SECURITY_TYPE %d", indicate->SECURITY_TYPE); slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.MSVarField.SenderID %s", HEXSTRING (string, indicate->MSVarField.SenderID)); slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.MSVarField.Count %d", indicate->MSVarField.CNT); slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.MSVarField.RunID %s", HEXSTRING (string, indicate->MSVarField.RunID)); slac_debug (session, 0, __func__, "CM_MNBC_SOUND.IND.MSVarField.RND %s", HEXSTRING (string, indicate->MSVarField.RND)); } #endif if (memcmp (session->PEV_MAC, indicate->ethernet.OSA, sizeof (session->PEV_MAC))) { slac_debug (session, session->exit, __func__, "Unexpected OSA"); } sounds++; } } else if (LE16TOH (homeplug->homeplug.MMTYPE) == (CM_ATTEN_PROFILE | MMTYPE_IND)) { struct cm_atten_profile_indicate * indicate = (struct cm_atten_profile_indicate *) (message); if (! memcmp (session->PEV_MAC, indicate->PEV_MAC, sizeof (session->PEV_MAC))) { slac_debug (session, 0, __func__, "<-- CM_ATTEN_PROFILE.IND (%d)", session->sounds); #if SLAC_DEBUG if (_anyset (session->flags, SLAC_VERBOSE)) { char string [256]; slac_debug (session, 0, __func__, "CM_ATTEN_PROFILE.PEV_MAC %s", HEXSTRING (string, indicate->PEV_MAC)); slac_debug (session, 0, __func__, "CM_ATTEN_PROFILE.NumGroups %d", indicate->NumGroups); slac_debug (session, 0, __func__, "CM_ATTEN_PROFILE.AAG %s", hexstring (string, sizeof (string), indicate->AAG, indicate->NumGroups)); } #endif for (session->NumGroups = 0; session->NumGroups < indicate->NumGroups; session->NumGroups++) { AAG [session->NumGroups] += indicate->AAG [session->NumGroups]; } session->NumGroups = indicate->NumGroups; session->sounds++; } } if (gettimeofday (& tc, NULL) == - 1) { slac_debug (session, 1, __func__, CANT_RESET_TIMER); } if ((MILLISECONDS (ts, tc) < timer) && (session->sounds < session->NUM_SOUNDS)) { continue; } if (session->sounds > 0) { for (session->NumGroups = 0; session->NumGroups < SLAC_GROUPS; ++ session->NumGroups) { session->AAG [session->NumGroups] = AAG [session->NumGroups] / session->sounds; } } return (0); } return (slac_debug (session, session->exit, __func__, "Sound timeout")); }
signed PHYSettings (struct channel * channel, struct phy_settings * settings, flag_t flags) { struct message message; signed packetsize; #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_enet_settings_request { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t MCONTROL; uint8_t AUTONEGOTIATE; uint8_t ADVCAPS; uint8_t ESPEED; uint8_t EDUPLEX; uint8_t EFLOWCONTROL; } * request = (struct vs_enet_settings_request *) (&message); struct __packed vs_enet_settings_confirm { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t MSTATUS; uint8_t ESPEED; uint8_t EDUPLEX; uint8_t ELINKSTATUS; uint8_t EFLOWCONTROL; } * confirm = (struct vs_enet_settings_confirm *) (&message); #ifndef __GNUC__ #pragma pack (pop) #endif char address [ETHER_ADDR_LEN * 3]; memset (&message, 0, sizeof (message)); EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_ENET_SETTINGS | MMTYPE_REQ)); request->MCONTROL = settings->MCONTROL; request->AUTONEGOTIATE = settings->AUTONEGOTIATE; request->ADVCAPS = settings->ADVCAPS; request->ESPEED = settings->ESPEED; request->EDUPLEX = settings->EDUPLEX; request->EFLOWCONTROL = settings->EFLOWCONTROL; if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) < 0) { error (1, errno, CHANNEL_CANTSEND); } while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0) { if (UnwantedMessage (&message, packetsize, 0, (VS_ENET_SETTINGS | MMTYPE_CNF))) { continue; } if ((confirm->MSTATUS == 1) || (confirm->MSTATUS == 3)) { error (0, 0, "%s: %s (0x%0X): ", PLC_WONTDOIT, MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS); continue; } if (_anyset (flags, PLC_ANALYSE)) { printf ("Bits Mode Link Flow\n"); printf ("%4d ", confirm->ESPEED); printf ("%4d ", confirm->EDUPLEX); printf ("%4d ", confirm->ELINKSTATUS); printf ("%4d\n", confirm->EFLOWCONTROL); } else { printf ("%s %s ", channel->ifname, hexstring (address, sizeof (address), channel->host, sizeof (channel->host))); printf ("Speed=%s ", rates [confirm->ESPEED]); printf ("Duplex=%s ", modes [confirm->EDUPLEX]); printf ("LinkStatus=%s ", links [confirm->ELINKSTATUS]); printf ("FlowControl=%s\n", flows [confirm->EFLOWCONTROL]); } } if (packetsize < 0) { error (1, errno, CHANNEL_CANTREAD); } return (0); }
static signed mdio (struct channel * channel, uint8_t mode, uint8_t phy, uint8_t reg, uint16_t * data) { struct message message; signed packetsize; #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_mdio_command_request { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t OPERATION; uint8_t PHY; uint8_t REG; uint16_t DATA; } * request = (struct vs_mdio_command_request *)(&message); struct __packed vs_mdio_command_confirm { struct ethernet_hdr ethernet; struct qualcomm_hdr qualcomm; uint8_t MSTATUS; uint16_t DATA; uint8_t PHY; uint8_t REG; } * confirm = (struct vs_mdio_command_confirm *)(&message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (&message, 0, sizeof (message)); EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_MDIO_COMMAND | MMTYPE_REQ)); request->OPERATION = mode; request->PHY = phy; request->REG = reg; request->DATA = HTOLE16 (*data); #if 1 printf (" phy 0x%02X", phy); printf (" reg 0x%02X", reg); printf (" data 0x%04X", * data); printf ("\n"); #endif if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) == -1) { error (1, errno, CHANNEL_CANTSEND); } while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0) { if (UnwantedMessage (&message, packetsize, 0, (VS_MDIO_COMMAND | MMTYPE_CNF))) { continue; } if (confirm->MSTATUS) { error (0, 0, "%s (%0X): %s", MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS, PLC_WONTDOIT); continue; } *data = confirm->DATA; return (0); } return (-1); }
signed PLCReadParameterBlock (struct channel * channel, struct message * message, void * memory, size_t extent) { uint8_t * buffer = (uint8_t *)(memory); #ifndef __GNUC__ #pragma pack (push,1) #endif struct __packed vs_rd_mod_request { struct ethernet_std ethernet; struct qualcomm_std 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_std ethernet; struct qualcomm_std qualcomm; uint8_t MSTATUS; uint8_t RESERVED1 [3]; uint8_t MODULEID; uint8_t RESERVED; uint16_t MLENGTH; uint32_t MOFFSET; uint32_t CHKSUM; uint8_t BUFFER [PLC_RECORD_SIZE]; } * confirm = (struct vs_rd_mod_confirm *) (message); #ifndef __GNUC__ #pragma pack (pop) #endif uint16_t length = 0; uint32_t offset = 0; signed actual = PLC_RECORD_SIZE; do { memset (message, 0, sizeof (* message)); EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ)); request->MODULEID = VS_MODULE_PIB; request->MLENGTH = HTOLE16 (actual); request->MOFFSET = HTOLE32 (offset); if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0) { error (1, errno, CHANNEL_CANTSEND); } if (readpacket (channel, message, sizeof (* message)) <= 0) { error (1, errno, CHANNEL_CANTREAD); } if (UnwantedMessage (message, sizeof (* confirm), 0, (VS_RD_MOD | MMTYPE_CNF))) { actual = PLC_RECORD_SIZE; offset = 0; continue; } if (confirm->MSTATUS) { error (1, ECANCELED, PLC_WONTDOIT); } if (LE16TOH (confirm->MLENGTH) != actual) { error (1, ECANCELED, PLC_ERR_LENGTH); } if (LE32TOH (confirm->MOFFSET) != offset) { error (1, ECANCELED, PLC_ERR_OFFSET); } actual = LE16TOH (confirm->MLENGTH); offset = LE32TOH (confirm->MOFFSET); if (checksum32 (confirm->BUFFER, actual, confirm->CHKSUM)) { error (1, ECANCELED, "Bad Packet Checksum"); } if (offset == length) { struct pib_header * pib_header = (struct pib_header *) (confirm->BUFFER); length = LE16TOH (pib_header->PIBLENGTH); } if ((offset + actual) > length) { actual = length - offset; } memcpy (buffer + offset, confirm->BUFFER, actual); offset += actual; extent -= actual; } while (offset < length); return (offset); }
int main (int argc, char const * argv []) { extern struct channel channel; struct message message; static char const * optv [] = { "e:i:qt:v", PUTOPTV_S_DIVINE, "Qualcomm Atheros Ethernet Frame Read Utility", "e x\tethertype is (x) [" LITERAL (EFRU_ETHERTYPE) "]", #if defined (WINPCAP) || defined (LIBPCAP) "i n\thost interface is (s) [" LITERAL (CHANNEL_ETHNUMBER) "]", #else "i s\thost interface is (n) [" LITERAL (CHANNEL_ETHDEVICE) "]", #endif "q\tsuppress normal output", "t n\tread timeout is (n) milliseconds [" LITERAL (CHANNEL_FOREVER) "]", "v\tverbose messages on stdout", (char const *) (0) }; flag_t flags = (flag_t)(0); signed length; signed c; if (getenv (EFRU_INTERFACE)) { #if defined (WINPCAP) || defined (LIBPCAP) channel.ifindex = atoi (getenv (EFRU_INTERFACE)); #else channel.ifname = strdup (getenv (EFRU_INTERFACE)); #endif } optind = 1; channel.type = EFRU_ETHERTYPE; channel.timeout = CHANNEL_FOREVER; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'e': channel.type = (uint16_t)(basespec (optarg, 16, sizeof (channel.type))); break; case 'i': #if defined (WIN32) channel.ifindex = atoi (optarg); #else channel.ifname = optarg; #endif break; case 'q': _setbits (flags, EFRU_SILENCE); break; case 't': channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX)); break; case 'v': _setbits (flags, EFRU_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ECANCELED, ERROR_TOOMANY); } openchannel (&channel); while ((length = readpacket (&channel, &message, sizeof (message))) >= 0) { hexdump (&message, 0, length, stdout); } closechannel (&channel); return (0); }
int main (int argc, char const * argv []) { extern struct channel channel; struct message message; static char const * optv [] = { "i:qt:v", PUTOPTV_S_DIVINE, "Qualcomm Atheros HomePlug AV Packet Monitor", #if defined (WINPCAP) "i s\thost interface is (s) [" CHANNEL_ETHDEVICE "]", #else "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]", #endif "q\tsuppress normal output", "t n\tread timeout is (n) milliseconds [" LITERAL (CHANNEL_TIMEOUT) "]", "v\tverbose messages on stdout", (char const *) (0) }; flag_t flags = (flag_t)(0); signed length; signed c; if (getenv (PLCDEVICE)) { #if defined (WINPCAP) channel.ifindex = atoi (getenv (PLCDEVICE)); #else channel.ifname = strdup (getenv (PLCDEVICE)); #endif } optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'i': #if defined (WIN32) channel.ifindex = atoi (optarg); #else channel.ifname = optarg; #endif break; case 'q': _setbits (flags, HPAV_SILENCE); break; case 't': channel.timeout = (unsigned)(uintspec (optarg, 0, UINT_MAX)); break; case 'v': _setbits (flags, HPAV_VERBOSE); break; default: break; } } argc -= optind; argv += optind; openchannel (&channel); while ((length = readpacket (&channel, &message, sizeof (message))) >= 0) { if (length > 0) { if (_allclr (flags, HPAV_SILENCE)) { MMEPeek (&message, length, stdout); } if (_anyset (flags, HPAV_VERBOSE)) { hexdump (&message, 0, length, stdout); } } } closechannel (&channel); return (0); }
int readversion(OCstate* state, OCURI* url, OCbytes* packet) { return readpacket(state,url,packet,OCVER,NULL); }
static void ReadKey1 (struct channel * channel, unsigned c, int key) { struct message message; static signed count = 0; signed packetsize; #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 RESERVED; uint16_t MLENGTH; uint32_t MOFFSET; uint8_t DAK [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 RESERVED1 [3]; uint8_t MODULEID; uint8_t RESERVED2; uint16_t MLENGTH; uint32_t MOFFSET; uint32_t MCHKSUM; struct simple_pib pib; } * confirm = (struct vs_rd_mod_confirm *)(&message); #ifndef __GNUC__ #pragma pack (pop) #endif memset (&message, 0, sizeof (message)); EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type); QualcommHeader (&request->qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ)); request->MODULEID = VS_MODULE_PIB; request->MLENGTH = HTOLE16 (PLC_RECORD_SIZE); request->MOFFSET = HTOLE32 (0); if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) < 0) { error (1, errno, CHANNEL_CANTSEND); } while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0) { if (UnwantedMessage (&message, packetsize, 0, (VS_RD_MOD | MMTYPE_CNF))) { continue; } if (confirm->MSTATUS) { error (0, 0, "%s (%0X): ", MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS); continue; } if (count++ > 0) { putc (c, stdout); } if (key == INT6KID_MAC) { hexout (confirm->pib.MAC, sizeof (confirm->pib.MAC), HEX_EXTENDER, 0, stdout); continue; } if (key == INT6KID_DAK) { hexout (confirm->pib.DAK, sizeof (confirm->pib.DAK), HEX_EXTENDER, 0, stdout); continue; } if (key == INT6KID_NMK) { hexout (confirm->pib.NMK, sizeof (confirm->pib.NMK), HEX_EXTENDER, 0, stdout); continue; } if (key == INT6KID_MFG) { confirm->pib.MFG [PIB_HFID_LEN - 1] = (char)(0); printf ("%s", confirm->pib.MFG); continue; } if (key == INT6KID_USR) { confirm->pib.USR [PIB_HFID_LEN - 1] = (char)(0); printf ("%s", confirm->pib.USR); continue; } if (key == INT6KID_NET) { confirm->pib.NET [PIB_HFID_LEN - 1] = (char)(0); printf ("%s", confirm->pib.NET); continue; } } if (packetsize < 0) { error (1, errno, CHANNEL_CANTREAD); } return; }