bool btsnoop_read_hci(struct btsnoop *btsnoop, struct timeval *tv, uint16_t *index, uint16_t *opcode, void *data, uint16_t *size) { struct btsnoop_pkt pkt; uint32_t toread, flags; uint64_t ts; uint8_t pkt_type; ssize_t len; if (!btsnoop || btsnoop->aborted) return false; if (btsnoop->pklg_format) return pklg_read_hci(btsnoop, tv, index, opcode, data, size); len = read(btsnoop->fd, &pkt, BTSNOOP_PKT_SIZE); if (len == 0) return false; if (len < 0 || len != BTSNOOP_PKT_SIZE) { btsnoop->aborted = true; return false; } toread = be32toh(pkt.size); if (toread > BTSNOOP_MAX_PACKET_SIZE) { btsnoop->aborted = true; return false; } flags = be32toh(pkt.flags); ts = be64toh(pkt.ts) - 0x00E03AB44A676000ll; tv->tv_sec = (ts / 1000000ll) + 946684800ll; tv->tv_usec = ts % 1000000ll; switch (btsnoop->type) { case BTSNOOP_TYPE_HCI: *index = 0; *opcode = get_opcode_from_flags(0xff, flags); break; case BTSNOOP_TYPE_UART: len = read(btsnoop->fd, &pkt_type, 1); if (len < 0) { btsnoop->aborted = true; return false; } toread--; *index = 0; *opcode = get_opcode_from_flags(pkt_type, flags); break; case BTSNOOP_TYPE_MONITOR: *index = flags >> 16; *opcode = flags & 0xffff; break; default: btsnoop->aborted = true; return false; } len = read(btsnoop->fd, data, toread); if (len < 0) { btsnoop->aborted = true; return false; } *size = toread; return true; }
static void ar5416_decode_rxstatus(struct if_ath_alq_payload *a) { struct ar5416_desc rxs; /* XXX assumes rxs is smaller than PAYLOAD_LEN! */ memcpy(&rxs, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] RXSTATUS: RxDone=%d, RxRate=0x%02x, TS=0x%08x\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid), MF(rxs.ds_rxstatus8, AR_RxDone), MS(rxs.ds_rxstatus0, AR_RxRate), rxs.ds_rxstatus2); printf(" link=0x%08x, data=0x%08x, ctl0=0x%08x, ctl2=0x%08x\n", rxs.ds_link, rxs.ds_data, rxs.ds_ctl0, rxs.ds_ctl1); /* status0 */ /* * XXX TODO: For AR9285, the chain 1 and chain 2 RSSI values * acutally contain the RX mixer configuration */ printf(" RSSICtl[0]=%d, RSSICtl[1]=%d, RSSICtl[2]=%d\n", MS(rxs.ds_rxstatus0, AR_RxRSSIAnt00), MS(rxs.ds_rxstatus0, AR_RxRSSIAnt01), MS(rxs.ds_rxstatus0, AR_RxRSSIAnt02)); /* status4 */ printf(" RSSIExt[0]=%d, RSSIExt[1]=%d, RSSIExt[2]=%d, RSSIComb=%d\n", MS(rxs.ds_rxstatus4, AR_RxRSSIAnt10), MS(rxs.ds_rxstatus4, AR_RxRSSIAnt11), MS(rxs.ds_rxstatus4, AR_RxRSSIAnt12), MS(rxs.ds_rxstatus4, AR_RxRSSICombined)); /* status2 */ printf(" RxTimestamp=0x%08x,", rxs.ds_rxstatus2); /* status1 */ printf(" DataLen=%d, RxMore=%d, NumDelim=%d\n", rxs.ds_rxstatus1 & AR_DataLen, MF(rxs.ds_rxstatus1, AR_RxMore), MS(rxs.ds_rxstatus1, AR_NumDelim)); /* status3 - RxRate however is for Owl 2.0 */ printf(" GI=%d, 2040=%d, RxRate=0x%02x, DupFrame=%d, RxAnt=0x%08x\n", MF(rxs.ds_rxstatus3, AR_GI), MF(rxs.ds_rxstatus3, AR_2040), MS(rxs.ds_rxstatus0, AR_RxRate), MF(rxs.ds_rxstatus3, AR_DupFrame), MS(rxs.ds_rxstatus3, AR_RxAntenna)); /* status5 */ /* status6 */ /* status7 */ printf(" RxEvm0=0x%08x, RxEvm1=0x%08x, RxEvm2=0x%08x\n", rxs.ds_rxstatus5, rxs.ds_rxstatus6, rxs.ds_rxstatus7); /* status8 */ printf(" RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n", MF(rxs.ds_rxstatus8, AR_RxDone), MF(rxs.ds_rxstatus8, AR_RxFrameOK), MF(rxs.ds_rxstatus8, AR_CRCErr), MF(rxs.ds_rxstatus8, AR_DecryptCRCErr)); printf(" PhyErr=%d, MichaelErr=%d, PreDelimCRCErr=%d, KeyIdxValid=%d\n", MF(rxs.ds_rxstatus8, AR_PHYErr), MF(rxs.ds_rxstatus8, AR_MichaelErr), MF(rxs.ds_rxstatus8, AR_PreDelimCRCErr), MF(rxs.ds_rxstatus8, AR_RxKeyIdxValid)); printf(" RxMoreAggr=%d, RxAggr=%d, PostDelimCRCErr=%d, HiRxChain=%d\n", MF(rxs.ds_rxstatus8, AR_RxMoreAggr), MF(rxs.ds_rxstatus8, AR_RxAggr), MF(rxs.ds_rxstatus8, AR_PostDelimCRCErr), MF(rxs.ds_rxstatus8, AR_HiRxChain)); /* If PHY error, print that out. Otherwise, the key index */ if (MF(rxs.ds_rxstatus8, AR_PHYErr)) printf(" PhyErrCode=0x%02x", MS(rxs.ds_rxstatus8, AR_PHYErrCode)); else printf(" KeyIdx=0x%02x", MS(rxs.ds_rxstatus8, AR_KeyIdx)); printf(", KeyMiss=%d\n", MF(rxs.ds_rxstatus8, AR_KeyMiss)); printf("\n ------\n"); }
static inline int32_t decode32(int32_t i) { return be32toh(i); }
static void ar9300_decode_txstatus(struct if_ath_alq_payload *a) { struct ar9300_txs txs; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txs, &a->payload, sizeof(struct ar9300_txs)); printf("[%u.%06u] [%llu] TXSTATUS\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid)); printf(" DescId=0x%08x\n", txs.status1); printf(" DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n", txs.ds_info & 0xff, MS(txs.ds_info, AR_tx_qcu_num), MS(txs.ds_info, AR_ctrl_stat), MS(txs.ds_info, AR_desc_id)); printf(" TxTimestamp=0x%08x\n", txs.status4); printf(" TxDone=%d, SeqNo=%d, TxOpExceed=%d, TXBFStatus=%d\n", MF(txs.status8, AR_tx_done), MS(txs.status8, AR_seq_num), MF(txs.status8, AR_tx_op_exceeded), MS(txs.status8, AR_TXBFStatus)); printf(" TXBfMismatch=%d, BFStreamMiss=%d, FinalTxIdx=%d\n", MF(txs.status8, AR_tx_bf_bw_mismatch), MF(txs.status8, AR_tx_bf_stream_miss), MS(txs.status8, AR_final_tx_idx)); printf(" TxBfDestMiss=%d, TxBfExpired=%d, PwrMgmt=%d, Tid=%d," " FastTsBit=%d\n", MF(txs.status8, AR_tx_bf_dest_miss), MF(txs.status8, AR_tx_bf_expired), MF(txs.status8, AR_power_mgmt), MS(txs.status8, AR_tx_tid), MF(txs.status8, AR_tx_fast_ts)); printf(" Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n", MF(txs.status3, AR_frm_xmit_ok), MF(txs.status3, AR_excessive_retries), MF(txs.status3, AR_fifounderrun), MF(txs.status3, AR_filtered)); printf(" DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d," " TxTimerExceeded=%d\n", MF(txs.status3, AR_tx_delim_underrun), MF(txs.status3, AR_tx_data_underrun), MF(txs.status3, AR_desc_cfg_err), MF(txs.status3, AR_tx_timer_expired)); printf(" RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n", MS(txs.status3, AR_rts_fail_cnt), MS(txs.status3, AR_data_fail_cnt), MS(txs.status3, AR_virt_retry_cnt)); printf(" RX RSSI 0 [%d %d %d]\n", MS(txs.status2, AR_tx_rssi_ant00), MS(txs.status2, AR_tx_rssi_ant01), MS(txs.status2, AR_tx_rssi_ant02)); printf(" RX RSSI 1 [%d %d %d] Comb=%d\n", MS(txs.status7, AR_tx_rssi_ant10), MS(txs.status7, AR_tx_rssi_ant11), MS(txs.status7, AR_tx_rssi_ant12), MS(txs.status7, AR_tx_rssi_combined)); printf(" BA Valid=%d\n", MF(txs.status2, AR_tx_ba_status)); printf(" BALow=0x%08x\n", txs.status5); printf(" BAHigh=0x%08x\n", txs.status6); printf("\n ------ \n"); }
static void usie_hip_rsp(struct usie_softc *sc, uint8_t *rsp, uint32_t len) { struct usie_hip *hip; struct usie_cns *cns; uint32_t i; uint32_t j; uint32_t off; uint8_t tmp[USIE_HIPCNS_MAX] __aligned(4); for (off = 0; (off + USIE_HIPCNS_MIN) <= len; off++) { uint8_t pad; while ((off < len) && (rsp[off] == USIE_HIP_FRM_CHR)) off++; /* Unstuff the bytes */ for (i = j = 0; ((i + off) < len) && (j < USIE_HIPCNS_MAX); i++) { if (rsp[i + off] == USIE_HIP_FRM_CHR) break; if (rsp[i + off] == USIE_HIP_ESC_CHR) { if ((i + off + 1) >= len) break; tmp[j++] = rsp[i++ + off + 1] ^ 0x20; } else { tmp[j++] = rsp[i + off]; } } off += i; DPRINTF("frame len=%d\n", j); if (j < sizeof(struct usie_hip)) { DPRINTF("too little data\n"); break; } /* * Make sure we are not reading the stack if something * is wrong. */ memset(tmp + j, 0, sizeof(tmp) - j); hip = (struct usie_hip *)tmp; DPRINTF("hip: len=%d msgID=%02x, param=%02x\n", be16toh(hip->len), hip->id, hip->param); pad = (hip->id & USIE_HIP_PAD) ? 1 : 0; if ((hip->id & USIE_HIP_MASK) == USIE_HIP_CNS2H) { cns = (struct usie_cns *)(((uint8_t *)(hip + 1)) + pad); if (j < (sizeof(struct usie_cns) + sizeof(struct usie_hip) + pad)) { DPRINTF("too little data\n"); break; } DPRINTF("cns: obj=%04x, op=%02x, rsv0=%02x, " "app=%08x, rsv1=%02x, len=%d\n", be16toh(cns->obj), cns->op, cns->rsv0, be32toh(cns->id), cns->rsv1, cns->len); if (cns->op & USIE_CNS_OP_ERR) DPRINTF("CnS error response\n"); else usie_cns_rsp(sc, cns); i = sizeof(struct usie_hip) + pad + sizeof(struct usie_cns); j = cns->len; } else { i = sizeof(struct usie_hip) + pad; j = be16toh(hip->len); } #ifdef USB_DEBUG if (usie_debug == 0) continue; while (i < USIE_HIPCNS_MAX && j > 0) { DPRINTF("param[0x%02x] = 0x%02x\n", i, tmp[i]); i++; j--; } #endif } }
/* Attach the interface. Allocate softc structures */ static int sln_attach(device_t dev) { struct sln_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->arpcom.ac_if; unsigned char eaddr[ETHER_ADDR_LEN]; int rid; int error = 0; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); /* TODO: power state change */ pci_enable_busmaster(dev); rid = SL_RID; sc->sln_res = bus_alloc_resource_any(dev, SL_RES, &rid, RF_ACTIVE); if (sc->sln_res == NULL) { device_printf(dev, "couldn't map ports/memory\n"); error = ENXIO; goto fail; } sc->sln_bustag = rman_get_bustag(sc->sln_res); sc->sln_bushandle = rman_get_bushandle(sc->sln_res); /* alloc pci irq */ rid = 0; sc->sln_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); if (sc->sln_irq == NULL) { device_printf(dev, "couldn't map interrupt\n"); bus_release_resource(dev, SL_RES, SL_RID, sc->sln_res); error = ENXIO; goto fail; } /* Get MAC address */ ((uint32_t *)(&eaddr))[0] = be32toh(SLN_READ_4(sc, SL_MAC_ADDR0)); ((uint16_t *)(&eaddr))[2] = be16toh(SLN_READ_4(sc, SL_MAC_ADDR1)); /* alloc rx buffer space */ sc->sln_bufdata.sln_rx_buf = contigmalloc(SL_RX_BUFLEN, M_DEVBUF, M_WAITOK, 0, 0xffffffff, PAGE_SIZE, 0); if (sc->sln_bufdata.sln_rx_buf == NULL) { device_printf(dev, "no memory for rx buffers!\n"); bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sln_irq); bus_release_resource(dev, SL_RES, SL_RID, sc->sln_res); error = ENXIO; goto fail; } callout_init(&sc->sln_state); ifp->if_softc = sc; ifp->if_mtu = ETHERMTU; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_init = sln_init; ifp->if_start = sln_tx; ifp->if_ioctl = sln_ioctl; ifp->if_watchdog = sln_watchdog; ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); ifq_set_ready(&ifp->if_snd); /* initial media */ ifmedia_init(&sc->ifmedia, 0, sln_media_upd, sln_media_stat); /* supported media types */ ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_HDX, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_HDX, 0, NULL); ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL); /* Choose a default media. */ ifmedia_set(&sc->ifmedia, IFM_ETHER | IFM_AUTO); ether_ifattach(ifp, eaddr, NULL); error = bus_setup_intr(dev, sc->sln_irq, INTR_MPSAFE, sln_interrupt, sc, &sc->sln_intrhand, ifp->if_serializer); if (error) { bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sln_irq); bus_release_resource(dev, SL_RES, SL_RID, sc->sln_res); ether_ifdetach(ifp); device_printf(dev, "couldn't set up irq\n"); goto fail; } ifp->if_cpuid = rman_get_cpuid(sc->sln_irq); KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus); return 0; fail: return error; }
static inline uint32_t ntoh32(const char* p) { uint32_t n; memcpy(&n, p, sizeof(n)); return be32toh(n); }
int main( int argc, char** argv ) { PGconn* t_PGconn = NULL; PGresult* t_PGresult_select = NULL; PGresult* t_PGresult; int t_returnCode = EXIT_FAILURE; int i = -1; int j; int k; int q; CURLcode t_curlCode; CURL* t_hEasy = NULL; char t_curlErrorMessage[CURL_ERROR_SIZE]; tDataBuffer t_responseBuffer = { NULL, 0 }; long t_httpResponseCode; json_object* j_getSTH = NULL; json_object* j_treeSize = NULL; json_object* j_timestamp = NULL; json_object* j_getEntries = NULL; json_object* j_entries = NULL; json_object* j_entry = NULL; json_object* j_leafInput = NULL; json_object* j_extraData = NULL; array_list* t_entriesArr = NULL; uint32_t t_entryID; uint32_t t_confirmedEntryID = -1; uint64_t t_timestamp; int64_t t_sthTimestamp; int t_treeSize; uint16_t t_logEntryType; char t_temp[255]; char* t_pointer; char* t_pointer1; char* t_b64Data; char* t_data = NULL; int32_t t_totalLength; X509* t_x509 = NULL; uint32_t t_certSize; char* t_query[32]; char* t_subjectName; uint8_t* t_cachedCACerts = NULL; uint32_t t_nCachedCACerts = 0; uint32_t t_nCertsInChain; EVP_MD_CTX t_mdctx; const EVP_MD* t_md; unsigned char t_sha256Hash_data[32]; uint32_t t_sha256Hash_size; /* Initialize the OpenSSL library */ OpenSSL_add_all_algorithms(); t_md = EVP_sha256(); EVP_MD_CTX_init(&t_mdctx); /* Install signal handlers */ signal(SIGHUP, signalHandler); signal(SIGINT, signalHandler); signal(SIGQUIT, signalHandler); signal(SIGTERM, signalHandler); for (q = 0; q < 32; q++) t_query[q] = malloc(128 * 1024); /* Connect to the database */ t_PGconn = PQconnectdb( "user=crtsh dbname=certwatch" " connect_timeout=5 client_encoding=auto" " application_name=ct_monitor" ); if (PQstatus(t_PGconn) != CONNECTION_OK) { printError("PQconnectdb()", PQerrorMessage(t_PGconn)); return EXIT_FAILURE; } printError("Connected OK", NULL); /* Get the latest CT Entry ID that we've added to the DB already */ sprintf( t_query[0], "SELECT ctl.ID, ctl.URL, ctl.LATEST_ENTRY_ID, ctl.NAME" " FROM ct_log ctl" " WHERE ctl.IS_ACTIVE" ); if (argc > 1) /* Only process one log */ sprintf( t_query[0] + strlen(t_query[0]), " AND ctl.ID = %s", argv[1] ); else /* Process all logs */ strcat( t_query[0], " ORDER BY ctl.ID" ); t_PGresult_select = PQexec( t_PGconn, t_query[0] ); if (PQresultStatus(t_PGresult_select) != PGRES_TUPLES_OK) { /* The SQL query failed */ printError("Query failed", PQerrorMessage(t_PGconn)); goto label_exit; } /* curl_global_init() must be called EXACTLY once */ t_curlCode = curl_global_init(CURL_GLOBAL_ALL); if (t_curlCode != CURLE_OK) { printError( "curl_global_init()", curl_easy_strerror(t_curlCode) ); /* Something went wrong, so we cannot continue */ return EXIT_FAILURE; } for (i = 0; i < PQntuples(t_PGresult_select); i++) { t_confirmedEntryID = -1; /* Initialize the "easy handle" */ t_hEasy = curl_easy_init(); if (!t_hEasy) { printError("curl_easy_init()", "returned NULL"); goto label_exit; } /* SETUP CURL BEHAVIOUR OPTIONS */ /* CURLOPT_NOPROGRESS: No progress meter */ CURL_EASY_SETOPT(CURLOPT_NOPROGRESS, 0) /* CURLOPT_NOSIGNAL: Don't use signals */ CURL_EASY_SETOPT(CURLOPT_NOSIGNAL, 1) /* SETUP CURL CALLBACK OPTIONS */ /* CURLOPT_WRITEFUNCTION: "Data Received" Callback Function */ CURL_EASY_SETOPT(CURLOPT_WRITEFUNCTION, curlDataReceivedFunction) /* CURLOPT_WRITEDATA: Data Pointer to pass to "Data Received" Callback Function */ CURL_EASY_SETOPT(CURLOPT_WRITEDATA, &t_responseBuffer) /* SETUP CURL ERROR OPTIONS */ /* CURLOPT_ERRORBUFFER: Buffer for potential error message */ CURL_EASY_SETOPT(CURLOPT_ERRORBUFFER, t_curlErrorMessage) /* SETUP CURL NETWORK OPTIONS */ /* CURLOPT_URL: The URL to deal with */ sprintf(t_temp, "%s/ct/v1/get-sth", PQgetvalue(t_PGresult_select, i, 1)); printError(t_temp, PQgetvalue(t_PGresult_select, i, 3)); CURL_EASY_SETOPT(CURLOPT_URL, t_temp) /* Use IPv4 rather than IPv6 */ CURL_EASY_SETOPT(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4) /* SETUP CURL HTTP OPTIONS */ /* CURLOPT_FOLLOWLOCATION: Don't follow "Location:" redirects */ CURL_EASY_SETOPT(CURLOPT_FOLLOWLOCATION, 0) /* SETUP CURL CONNECTION OPTIONS */ /* CURLOPT_TIMEOUT: Transfer Timeout (in seconds) */ CURL_EASY_SETOPT(CURLOPT_TIMEOUT, 300) /* CURLOPT_CONNECTTIMEOUT: Connect Timeout (in seconds) */ CURL_EASY_SETOPT(CURLOPT_CONNECTTIMEOUT, 300) /* Perform the transfer */ t_curlCode = curl_easy_perform(t_hEasy); if (t_curlCode != CURLE_OK) { printError("curl_easy_perform()", t_curlErrorMessage); goto label_exit; } /* Get the HTTP response code */ t_curlCode = curl_easy_getinfo( t_hEasy, CURLINFO_RESPONSE_CODE, &t_httpResponseCode ); if (t_curlCode != CURLE_OK) { printError("curl_easy_getinfo()", t_curlErrorMessage); goto label_exit; } else if (t_httpResponseCode != 200) { printError( "curl_easy_getinfo()", "Unexpected HTTP Response Code" ); goto label_exit; } if (PQgetisnull(t_PGresult_select, i, 2)) t_entryID = -1; else t_entryID = strtoul( PQgetvalue(t_PGresult_select, i, 2), NULL, 10 ); printf("Highest Entry ID stored: %d\n", t_entryID); j_getSTH = json_tokener_parse(t_responseBuffer.data); if (!json_object_object_get_ex(j_getSTH, "tree_size", &j_treeSize)) goto label_exit; t_treeSize = json_object_get_int(j_treeSize); printf("Current Tree Size: %d\n", t_treeSize); if (!json_object_object_get_ex(j_getSTH, "timestamp", &j_timestamp)) goto label_exit; t_sthTimestamp = json_object_get_int64(j_timestamp); printf("Timestamp: %" LENGTH64 "d\n", t_sthTimestamp); if (json_object_put(j_getSTH) != 1) { printError("json_object_put(j_getSTH)", "Did not return 1"); goto label_exit; } free(t_responseBuffer.data); t_responseBuffer.data = NULL; t_responseBuffer.size = 0; /* TODO: Verify the STH signature */ for (t_entryID++; t_entryID < t_treeSize; t_entryID = t_confirmedEntryID + 1) { sprintf( t_temp, "%s/ct/v1/get-entries?start=%d&end=%d", PQgetvalue(t_PGresult_select, i, 1), t_entryID, (t_treeSize > (t_entryID + 1023)) ? (t_entryID + 1023) : (t_treeSize - 1) ); printError(t_temp, NULL); CURL_EASY_SETOPT(CURLOPT_URL, t_temp) /* Perform the transfer */ t_curlCode = curl_easy_perform(t_hEasy); if (t_curlCode != CURLE_OK) { printError("curl_easy_perform()", t_curlErrorMessage); goto label_exit; } /* Get the HTTP response code */ t_curlCode = curl_easy_getinfo( t_hEasy, CURLINFO_RESPONSE_CODE, &t_httpResponseCode ); if (t_curlCode != CURLE_OK) { printError("curl_easy_getinfo()", t_curlErrorMessage); goto label_exit; } else if (t_httpResponseCode != 200) { printError( "curl_easy_getinfo()", "Unexpected HTTP Response Code" ); goto label_exit; } /* Update the "Last Contacted" timestamp */ sprintf( t_query[0], "UPDATE ct_log" " SET LATEST_UPDATE=statement_timestamp()" " WHERE ID=%s", PQgetvalue(t_PGresult_select, i, 0) ); t_PGresult = PQexec(t_PGconn, t_query[0]); if (PQresultStatus(t_PGresult) != PGRES_COMMAND_OK) { /* The SQL query failed */ printError( "UPDATE Query failed", PQerrorMessage(t_PGconn) ); } PQclear(t_PGresult); /* Parse the JSON response */ j_getEntries = json_tokener_parse(t_responseBuffer.data); if (!json_object_object_get_ex(j_getEntries, "entries", &j_entries)) goto label_exit; t_entriesArr = json_object_get_array(j_entries); for (j = 0; j < json_object_array_length(j_entries); j++) { j_entry = array_list_get_idx(t_entriesArr, j); if (!json_object_object_get_ex(j_entry, "leaf_input", &j_leafInput)) goto label_exit; /* Decode the Base64 leaf_input string */ t_b64Data = (char*)json_object_get_string(j_leafInput); t_data = NULL; Base64Decode(t_b64Data, &t_data); if (!t_data) { printError("Base64 decode error", ""); goto label_exit; } /* Check the header fields */ if (*(unsigned char*)t_data != 0) { sprintf( t_temp, "%u", *(unsigned char*)t_data ); printError("Unexpected Version", t_temp); goto label_exit; } if (*(unsigned char*)(t_data + 1) != 0) { sprintf( t_temp, "%u", *(unsigned char*)(t_data + 1) ); printError("Unexpected MerkleLeafType", t_temp); goto label_exit; } t_timestamp = be64toh(*(uint64_t*)(t_data + 2)); t_logEntryType = be16toh(*(uint16_t*)(t_data + 10)); if (t_logEntryType == 1) { /* Precertificate. The leaf_input contains a SHA-256 hash of the Issuer Public Key, then the TBSCertificate. Ignore both of these. The submitted Precertificate is the first cert in the extra_data */ } else if (t_logEntryType == 0) { /* Parse the certificate */ t_certSize = 0; memcpy(((char*)&t_certSize) + 1, t_data + 12, 3); t_certSize = be32toh(t_certSize); printf("%d: ", (t_entryID + j)); t_pointer = t_data + 15; t_x509 = d2i_X509( NULL, (const unsigned char**)&t_pointer, t_certSize ); if (t_x509) { t_subjectName = X509_NAME_oneline( X509_get_subject_name(t_x509), NULL, 0 ); if (t_subjectName) { printf("%s\n", t_subjectName); OPENSSL_free(t_subjectName); } X509_free(t_x509); if (t_certSize != (t_pointer - (t_data + 15))) { printError("Additional data after EE cert", t_b64Data); t_certSize = t_pointer - (t_data + 15); } } else printError("Failed to decode EE cert", t_b64Data); /* Construct the "INSERT" query */ sprintf(t_query[0], "SELECT import_ct_cert(%s::smallint, %d, %" LENGTH64 "u, E'\\\\x", PQgetvalue(t_PGresult_select, i, 0), (t_entryID + j), t_timestamp); for (k = 0; k < t_certSize; k++) sprintf( t_query[0] + strlen(t_query[0]), "%02X", *(unsigned char*)(t_data + 15 + k)); strcat(t_query[0], "')"); } else { sprintf(t_temp, "%u", t_logEntryType); printError("Unexpected LogEntryType", t_temp); goto label_exit; } free(t_data); t_nCertsInChain = 1; if (!json_object_object_get_ex(j_entry, "extra_data", &j_extraData)) goto label_addCerts; /* Decode the Base64 extra_data string */ t_b64Data = (char*)json_object_get_string(j_extraData); t_data = NULL; Base64Decode(t_b64Data, &t_data); if (!t_data) { printError("Base64 decode error", ""); goto label_exit; } t_pointer1 = t_data; if (t_logEntryType == 1) { t_certSize = 0; memcpy(((char*)&t_certSize) + 1, t_pointer1, 3); t_certSize = be32toh(t_certSize); t_pointer1 += 3; t_pointer = t_pointer1; t_x509 = d2i_X509( NULL, (const unsigned char**)&t_pointer, t_certSize ); if (!t_x509) { printError("Failed to decode Precertificate", t_b64Data); goto label_exit; } if (t_certSize != (t_pointer - t_pointer1)) { printError("Additional data after Precertificate", t_b64Data); t_certSize = t_pointer - t_pointer1; } t_subjectName = X509_NAME_oneline( X509_get_subject_name(t_x509), NULL, 0 ); printf("Precertificate: %s\n", t_subjectName); X509_free(t_x509); if (t_subjectName) OPENSSL_free(t_subjectName); /* Construct the "INSERT" query */ sprintf(t_query[0], "SELECT import_ct_cert(%s::smallint, %d, %" LENGTH64 "u, E'\\\\x", PQgetvalue(t_PGresult_select, i, 0), (t_entryID + j), t_timestamp); for (k = 0; k < t_certSize; k++) sprintf( t_query[0] + strlen(t_query[0]), "%02X", *(unsigned char*)(t_pointer1 + k)); strcat(t_query[0], "')"); t_pointer1 = t_pointer; } /* Find the total length of the CA certificate array */ t_totalLength = 0; memcpy(((char*)&t_totalLength) + 1, t_pointer1, 3); t_totalLength = be32toh(t_totalLength); t_pointer1 += 3; /* Parse each CA Certificate */ while (t_totalLength > 0) { t_certSize = 0; memcpy(((char*)&t_certSize) + 1, t_pointer1, 3); t_certSize = be32toh(t_certSize); t_totalLength -= 3; t_pointer1 += 3; t_pointer = t_pointer1; t_x509 = d2i_X509( NULL, (const unsigned char**)&t_pointer, t_certSize ); if (!t_x509) { printError("Failed to decode CA cert", t_b64Data); goto label_exit; } if (t_certSize != (t_pointer - t_pointer1)) { printError("Additional data after CA cert", t_b64Data); t_certSize = t_pointer - t_pointer1; } t_subjectName = X509_NAME_oneline( X509_get_subject_name(t_x509), NULL, 0 ); printf("CA: %s", t_subjectName); X509_free(t_x509); if (t_subjectName) OPENSSL_free(t_subjectName); /* Generate SHA-256(CACertificate) */ EVP_DigestInit_ex(&t_mdctx, t_md, NULL); EVP_DigestUpdate(&t_mdctx, t_pointer1, t_certSize); EVP_DigestFinal_ex(&t_mdctx, t_sha256Hash_data, &t_sha256Hash_size); if ((!t_cachedCACerts) || (!bsearch(t_sha256Hash_data, t_cachedCACerts, t_nCachedCACerts, 32, compareSHA256Hashes))) { /* We've not cached this CA Certificate yet, so let's "INSERT" it and cache it */ /* Construct the "INSERT" query */ strcpy(t_query[t_nCertsInChain], "SELECT import_cert(E'\\\\x"); for (k = 0; k < t_certSize; k++) sprintf( t_query[t_nCertsInChain] + strlen(t_query[t_nCertsInChain]), "%02X", *(unsigned char*)(t_pointer1 + k)); strcat(t_query[t_nCertsInChain], "')"); t_nCertsInChain++; /* Cache this SHA-256(CACertificate), then re-sort the list */ t_nCachedCACerts++; t_cachedCACerts = realloc(t_cachedCACerts, t_nCachedCACerts * 32); (void)memcpy(t_cachedCACerts + ((t_nCachedCACerts - 1) * 32), t_sha256Hash_data, t_sha256Hash_size); qsort(t_cachedCACerts, t_nCachedCACerts, 32, compareSHA256Hashes); } else printf(" (Already cached)"); printf("\n"); t_totalLength -= (t_pointer - t_pointer1); t_pointer1 = t_pointer; } free(t_data); label_addCerts: /* Execute the "INSERT" quer(ies) */ printf("Import %d cert%s: ", t_nCertsInChain, (t_nCertsInChain == 1) ? "" : "s"); for (q = t_nCertsInChain - 1; q >= 0; q--) { t_PGresult = PQexec(t_PGconn, t_query[q]); if (PQresultStatus(t_PGresult) != PGRES_TUPLES_OK) { /* The SQL query failed */ printError("Query failed", PQerrorMessage(t_PGconn)); goto label_exit; } else if (PQgetisnull(t_PGresult, 0, 0)) { /* The SQL query failed */ printError("Query failed", t_query[q]); goto label_exit; } PQclear(t_PGresult); } printf("OK\n"); t_confirmedEntryID = t_entryID + j; if (g_terminateNow) goto label_exit; printf("\n"); } if (json_object_put(j_getEntries) != 1) { printError( "json_object_put(j_getEntries)", "Did not return 1" ); goto label_exit; } free(t_responseBuffer.data); t_responseBuffer.data = NULL; t_responseBuffer.size = 0; if (g_terminateNow) goto label_exit; } /* Cleanup the "easy handle" */ curl_easy_cleanup(t_hEasy); t_hEasy = NULL; if (t_confirmedEntryID == -1) t_entryID--; else t_entryID = t_confirmedEntryID; /* Update the "Latest STH" timestamp, now that we've processed all of the entries covered by this STH */ sprintf( t_query[0], "UPDATE ct_log" " SET LATEST_UPDATE=statement_timestamp()," " LATEST_STH_TIMESTAMP=TIMESTAMP WITH TIME ZONE 'epoch'" " + interval'%" LENGTH64 "d seconds'" " + interval'%" LENGTH64 "d milliseconds'" " WHERE ID=%s", t_sthTimestamp / 1000, t_sthTimestamp % 1000, PQgetvalue(t_PGresult_select, i, 0) ); t_PGresult = PQexec(t_PGconn, t_query[0]); if (PQresultStatus(t_PGresult) != PGRES_COMMAND_OK) { /* The SQL query failed */ printError( "UPDATE Query failed", PQerrorMessage(t_PGconn) ); } PQclear(t_PGresult); } t_returnCode = EXIT_SUCCESS; label_exit: if (t_returnCode == EXIT_FAILURE) if (t_confirmedEntryID != -1) { sprintf( t_query[0], "UPDATE ct_log" " SET LATEST_UPDATE=statement_timestamp()" " WHERE ID=%s", PQgetvalue(t_PGresult_select, i, 0) ); t_PGresult = PQexec(t_PGconn, t_query[0]); if (PQresultStatus(t_PGresult) != PGRES_COMMAND_OK) { /* The SQL query failed */ printError( "UPDATE Query failed", PQerrorMessage(t_PGconn) ); } PQclear(t_PGresult); } printError("Terminated", NULL); /* Clear the query results */ if (t_PGresult_select) PQclear(t_PGresult_select); /* Close this DB connection */ if (t_PGconn) PQfinish(t_PGconn); /* Free the Response Buffer */ if (t_responseBuffer.data) free(t_responseBuffer.data); /* Cleanup the "easy handle" */ if (t_hEasy) curl_easy_cleanup(t_hEasy); /* curl_global_cleanup() must be called EXACTLY once */ curl_global_cleanup(); for (q = 0; q < 32; q++) if (t_query[q]) free(t_query[q]); if (t_cachedCACerts) free(t_cachedCACerts); EVP_MD_CTX_cleanup(&t_mdctx); return t_returnCode; }
int protocol_recv_request_send_reply (struct connection *conn) { int r; struct request request; uint16_t cmd, flags; uint32_t magic, count, error = 0; uint64_t offset; char *buf = NULL; CLEANUP_EXTENTS_FREE struct nbdkit_extents *extents = NULL; /* Read the request packet. */ { ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&conn->read_lock); r = connection_get_status (conn); if (r <= 0) return r; r = conn->recv (conn, &request, sizeof request); if (r == -1) { nbdkit_error ("read request: %m"); return connection_set_status (conn, -1); } if (r == 0) { debug ("client closed input socket, closing connection"); return connection_set_status (conn, 0); /* disconnect */ } magic = be32toh (request.magic); if (magic != NBD_REQUEST_MAGIC) { nbdkit_error ("invalid request: 'magic' field is incorrect (0x%x)", magic); return connection_set_status (conn, -1); } flags = be16toh (request.flags); cmd = be16toh (request.type); offset = be64toh (request.offset); count = be32toh (request.count); if (cmd == NBD_CMD_DISC) { debug ("client sent %s, closing connection", name_of_nbd_cmd (cmd)); return connection_set_status (conn, 0); /* disconnect */ } /* Validate the request. */ if (!validate_request (conn, cmd, flags, offset, count, &error)) { if (cmd == NBD_CMD_WRITE && skip_over_write_buffer (conn->sockin, count) < 0) return connection_set_status (conn, -1); goto send_reply; } /* Get the data buffer used for either read or write requests. * This is a common per-thread data buffer, it must not be freed. */ if (cmd == NBD_CMD_READ || cmd == NBD_CMD_WRITE) { buf = threadlocal_buffer ((size_t) count); if (buf == NULL) { error = ENOMEM; if (cmd == NBD_CMD_WRITE && skip_over_write_buffer (conn->sockin, count) < 0) return connection_set_status (conn, -1); goto send_reply; } } /* Allocate the extents list for block status only. */ if (cmd == NBD_CMD_BLOCK_STATUS) { extents = nbdkit_extents_new (offset, conn->exportsize); if (extents == NULL) { error = ENOMEM; goto send_reply; } } /* Receive the write data buffer. */ if (cmd == NBD_CMD_WRITE) { r = conn->recv (conn, buf, count); if (r == 0) { errno = EBADMSG; r = -1; } if (r == -1) { nbdkit_error ("read data: %s: %m", name_of_nbd_cmd (cmd)); return connection_set_status (conn, -1); } } } /* Perform the request. Only this part happens inside the request lock. */ if (quit || !connection_get_status (conn)) { error = ESHUTDOWN; } else { lock_request (conn); error = handle_request (conn, cmd, flags, offset, count, buf, extents); assert ((int) error >= 0); unlock_request (conn); } /* Send the reply packet. */ send_reply: if (connection_get_status (conn) < 0) return -1; if (error != 0) { /* Since we're about to send only the limited NBD_E* errno to the * client, don't lose the information about what really happened * on the server side. Make sure there is a way for the operator * to retrieve the real error. */ debug ("sending error reply: %s", strerror (error)); } /* Currently we prefer to send simple replies for everything except * where we have to (ie. NBD_CMD_READ and NBD_CMD_BLOCK_STATUS when * structured_replies have been negotiated). However this prevents * us from sending human-readable error messages to the client, so * we should reconsider this in future. */ if (conn->structured_replies && (cmd == NBD_CMD_READ || cmd == NBD_CMD_BLOCK_STATUS)) { if (!error) { if (cmd == NBD_CMD_READ) return send_structured_reply_read (conn, request.handle, cmd, buf, count, offset); else /* NBD_CMD_BLOCK_STATUS */ return send_structured_reply_block_status (conn, request.handle, cmd, flags, count, offset, extents); } else return send_structured_reply_error (conn, request.handle, cmd, flags, error); } else return send_simple_reply (conn, request.handle, cmd, buf, count, error); }
array<CArray8UInt32, 3> CalcSCryptHash_80_3way(const uint32_t input[20]) { DECLSPEC_ALIGN(128) uint32_t tstate[16][4], ostate[8][4], istate[8][4], bufPasswd[32][4], buf[32][4], w[3*16*2]; for (int i=0; i<19; ++i) bufPasswd[i][0] = bufPasswd[i][1] = bufPasswd[i][2] = be32toh(input[i]); bufPasswd[19][0] = be32toh(input[19]); bufPasswd[19][1] = be32toh(input[19]+1); bufPasswd[19][2] = be32toh(input[19]+2); SHA256::Init4Way(tstate); memcpy(bufPasswd[20], s_InputPad, sizeof s_InputPad); Sha256Update_4way_x86x64Sse2(tstate, bufPasswd); Sha256Update_4way_x86x64Sse2(tstate, bufPasswd+16); SHA256::Init4Way(ostate); for (int i=0; i<8; ++i) { buf[i][0] = tstate[i][0] ^ 0x5C5C5C5C; buf[i][1] = tstate[i][1] ^ 0x5C5C5C5C; buf[i][2] = tstate[i][2] ^ 0x5C5C5C5C; buf[i][3] = tstate[i][3] ^ 0x5C5C5C5C; } memset(buf+8, 0x5C, 8*16); Sha256Update_4way_x86x64Sse2(ostate, buf); for (int i=0; i<8; ++i) { buf[i][0] = tstate[i][0] ^ 0x36363636; buf[i][1] = tstate[i][1] ^ 0x36363636; buf[i][2] = tstate[i][2] ^ 0x36363636; buf[i][3] = tstate[i][3] ^ 0x36363636; } memset(buf+8, 0x36, 8*16); SHA256::Init4Way(tstate); Sha256Update_4way_x86x64Sse2(tstate, buf); memcpy(istate, tstate, sizeof istate); Sha256Update_4way_x86x64Sse2(istate, bufPasswd); for (int k=0; k<3; ++k) { DECLSPEC_ALIGN(128) uint32_t ist[16][4], ost[8][4]; for (int i=0; i<8; ++i) { ist[i][0] = ist[i][1] = ist[i][2] = ist[i][3] = istate[i][k]; ost[i][0] = ost[i][1] = ost[i][2] = ost[i][3] = ostate[i][k]; } for (int i=0; i<4; ++i) buf[i][0] = buf[i][1] = buf[i][2] = buf[i][3] = bufPasswd[16+i][k]; memcpy(buf[4], s_InnerPad, sizeof s_InnerPad); Sha256Update_4way_x86x64Sse2(ist, buf); memcpy(ist[8], s_OuterPad, sizeof s_OuterPad); Sha256Update_4way_x86x64Sse2(ost, ist); uint32_t *d = w+32*k; d[0] = swap32(ost[0][0]); d[1] = swap32(ost[5][0]); d[2] = swap32(ost[2][1]); d[3] = swap32(ost[7][1]); d[4] = swap32(ost[4][1]); d[5] = swap32(ost[1][0]); d[6] = swap32(ost[6][0]); d[7] = swap32(ost[3][1]); d[8] = swap32(ost[0][1]); d[9] = swap32(ost[5][1]); d[10] = swap32(ost[2][0]); d[11] = swap32(ost[7][0]); d[12] = swap32(ost[4][0]); d[13] = swap32(ost[1][1]); d[14] = swap32(ost[6][1]); d[15] = swap32(ost[3][0]); d[16+0] = swap32(ost[0][2]); d[16+1] = swap32(ost[5][2]); d[16+2] = swap32(ost[2][3]); d[16+3] = swap32(ost[7][3]); d[16+4] = swap32(ost[4][3]); d[16+5] = swap32(ost[1][2]); d[16+6] = swap32(ost[6][2]); d[16+7] = swap32(ost[3][3]); d[16+8] = swap32(ost[0][3]); d[16+9] = swap32(ost[5][3]); d[16+10] = swap32(ost[2][2]); d[16+11] = swap32(ost[7][2]); d[16+12] = swap32(ost[4][2]); d[16+13] = swap32(ost[1][3]); d[16+14] = swap32(ost[6][3]); d[16+15] = swap32(ost[3][2]); } AlignedMem am((3*1025*32)*sizeof(uint32_t), 128); ScryptCore_x64_3way(w, (uint32_t*)am.get()); uint32_t *s = w; for (int k=0; k<3; ++k) { buf[0 ][k] = swap32(s[0]); buf[5 ][k] = swap32(s[1]); buf[10 ][k] = swap32(s[2]); buf[15 ][k] = swap32(s[3]); buf[12 ][k] = swap32(s[4]); buf[1 ][k] = swap32(s[5]); buf[6 ][k] = swap32(s[6]); buf[11 ][k] = swap32(s[7]); buf[8 ][k] = swap32(s[8]); buf[13 ][k] = swap32(s[9]); buf[2 ][k] = swap32(s[10]); buf[7 ][k] = swap32(s[11]); buf[4 ][k] = swap32(s[12]); buf[9 ][k] = swap32(s[13]); buf[14 ][k] = swap32(s[14]); buf[3 ][k] = swap32(s[15]); s += 32; } Sha256Update_4way_x86x64Sse2(tstate, buf); s = w+16; for (int k=0; k<3; ++k) { buf[0 ][k] = swap32(s[0]); buf[5 ][k] = swap32(s[1]); buf[10 ][k] = swap32(s[2]); buf[15 ][k] = swap32(s[3]); buf[12 ][k] = swap32(s[4]); buf[1 ][k] = swap32(s[5]); buf[6 ][k] = swap32(s[6]); buf[11 ][k] = swap32(s[7]); buf[8 ][k] = swap32(s[8]); buf[13 ][k] = swap32(s[9]); buf[2 ][k] = swap32(s[10]); buf[7 ][k] = swap32(s[11]); buf[4 ][k] = swap32(s[12]); buf[9 ][k] = swap32(s[13]); buf[14 ][k] = swap32(s[14]); buf[3 ][k] = swap32(s[15]); s += 32; } Sha256Update_4way_x86x64Sse2(tstate, buf); Sha256Update_4way_x86x64Sse2(tstate, s_IhashFinal_4way); memcpy(tstate[8], s_OuterPad, sizeof s_OuterPad); Sha256Update_4way_x86x64Sse2(ostate, tstate); array<CArray8UInt32, 3> r; for (int i=0; i<8; ++i) { r[0][i] = htobe32(ostate[i][0]); r[1][i] = htobe32(ostate[i][1]); r[2][i] = htobe32(ostate[i][2]); } return r; }
void stream_decode(struct Stream* self, const uchar* buf, int depth) { /* Extract SPEAD packet headers. */ const uchar magic = buf[0]; const uchar version = buf[1]; if (magic != 'S' || version != (uchar)4) return; const uchar item_id_bits = buf[2] * 8 - 1; const uchar heap_address_bits = buf[3] * 8; const uchar num_items = buf[7]; /* Get pointers to items and payload start. */ const uint64_t* items = (const uint64_t*) &buf[8]; const uint64_t mask_addr = (1ull << heap_address_bits) - 1; const uint64_t mask_id = (1ull << item_id_bits) - 1; const uchar* payload_start = (const uchar*) &items[num_items]; /* Heap data. */ int packet_has_header_data = 0, packet_has_stream_control = 0; uint32_t timestamp_count = 0, timestamp_fraction = 0; uint64_t scan_id = 0; size_t packet_payload_length = 0; size_t heap_offset = 0, heap_size = 0; size_t vis_data_start = 0; /* Iterate ItemPointers. */ for (uchar i = 0; i < num_items; ++i) { const uint64_t item = be64toh(items[i]); /*const uint64_t immediate = item & (1ull << 63);*/ const uint64_t item_addr = item & mask_addr; const uint64_t item_id = (item >> heap_address_bits) & mask_id; switch (item_id) { case 0x0: /* NULL - ignore. */ break; case 0x1: /* Heap counter (immediate addressing, big endian). */ if (depth == 0) self->heap_count = (int) item_addr - 2; break; case 0x2: /* Heap size (immediate addressing, big endian). */ heap_size = item_addr; break; case 0x3: /* Heap offset (immediate addressing, big endian). */ heap_offset = (size_t) item_addr; break; case 0x4: /* Packet payload length (immediate addressing, big endian). */ packet_payload_length = (size_t) item_addr; break; case 0x5: /* Nested item descriptor (recursive call). */ /*stream_decode(self, &payload_start[item_addr], depth + 1);*/ break; case 0x6: /* Stream control messages (immediate addressing, big endian). */ packet_has_stream_control = 1; if (item_addr == 2) self->done = 1; break; case 0x10: /* Item descriptor name (absolute addressing). */ case 0x11: /* Item descriptor desc. (absolute addressing). */ case 0x12: /* Item descriptor shape (absolute addressing). */ case 0x13: /* Item descriptor type (absolute addressing). */ case 0x14: /* Item descriptor ID (immediate addressing). */ case 0x15: /* Item descriptor DataType (absolute addressing). */ break; case 0x6000: /* Visibility timestamp count (immediate addressing). */ timestamp_count = be32toh((uint32_t) item_addr); packet_has_header_data = 1; break; case 0x6001: /* Visibility timestamp fraction (immediate addressing). */ timestamp_fraction = be32toh((uint32_t) item_addr); packet_has_header_data = 1; break; case 0x6005: /* Visibility baseline count (immediate addressing). */ self->receiver->num_baselines = be32toh((uint32_t) item_addr); packet_has_header_data = 1; break; case 0x6008: /* Scan ID (absolute addressing). */ scan_id = *( (uint64_t*)(payload_start + item_addr) ); packet_has_header_data = 1; break; case 0x600A: /* Visibility data (absolute addressing). */ self->vis_data_heap_offset = (size_t) item_addr; vis_data_start = (size_t) item_addr; break; default: /*printf("Heap %3d ID: %#6llx, %s: %llu\n", self->heap_count, item_id, immediate ? "VAL" : "ptr", item_addr);*/ break; } } if (0 && !packet_has_stream_control) printf("==== Packet in heap %3d " "(heap offset %zu/%zu, payload length %zu)\n", self->heap_count, heap_offset, heap_size, packet_payload_length); if (0 && packet_has_header_data) { printf(" heap : %d\n", self->heap_count); printf(" timestamp_count : %" PRIu32 "\n", timestamp_count); printf(" timestamp_fraction : %" PRIu32 "\n", timestamp_fraction); printf(" scan_id : %" PRIu64 "\n", scan_id); printf(" num_baselines : %d\n", self->receiver->num_baselines); } if (!packet_has_stream_control && self->vis_data_heap_offset > 0 && self->receiver->num_baselines > 0) { const double timestamp = tmr_get_timestamp(); const size_t vis_data_length = packet_payload_length - vis_data_start; /*printf("Visibility data length: %zu bytes\n", vis_data_length);*/ struct Buffer* buf = receiver_buffer( self->receiver, self->heap_count, vis_data_length, timestamp); if (buf) { const uchar* src_addr = payload_start + vis_data_start; const int i_time = self->heap_count - buf->heap_id_start; const int i_chan = self->stream_id; uchar* dst_addr = ((uchar*) buf->vis_data) + heap_offset - self->vis_data_heap_offset + vis_data_start + buf->block_size * (i_time * buf->num_channels + i_chan); tmr_resume(self->tmr_memcpy); memcpy(dst_addr, src_addr, vis_data_length); tmr_pause(self->tmr_memcpy); self->recv_byte_counter += vis_data_length; } else { self->dump_byte_counter += vis_data_length; } } }
static int alloc_nm_txq_hwq(struct port_info *pi, struct sge_nm_txq *nm_txq) { int rc, cntxt_id; size_t len; struct adapter *sc = pi->adapter; struct netmap_adapter *na = NA(pi->nm_ifp); struct fw_eq_eth_cmd c; MPASS(na != NULL); MPASS(nm_txq->desc != NULL); len = na->num_tx_desc * EQ_ESIZE + spg_len; bzero(nm_txq->desc, len); bzero(&c, sizeof(c)); c.op_to_vfn = htobe32(V_FW_CMD_OP(FW_EQ_ETH_CMD) | F_FW_CMD_REQUEST | F_FW_CMD_WRITE | F_FW_CMD_EXEC | V_FW_EQ_ETH_CMD_PFN(sc->pf) | V_FW_EQ_ETH_CMD_VFN(0)); c.alloc_to_len16 = htobe32(F_FW_EQ_ETH_CMD_ALLOC | F_FW_EQ_ETH_CMD_EQSTART | FW_LEN16(c)); c.autoequiqe_to_viid = htobe32(V_FW_EQ_ETH_CMD_VIID(pi->nm_viid)); c.fetchszm_to_iqid = htobe32(V_FW_EQ_ETH_CMD_HOSTFCMODE(X_HOSTFCMODE_NONE) | V_FW_EQ_ETH_CMD_PCIECHN(pi->tx_chan) | F_FW_EQ_ETH_CMD_FETCHRO | V_FW_EQ_ETH_CMD_IQID(sc->sge.nm_rxq[nm_txq->iqidx].iq_cntxt_id)); c.dcaen_to_eqsize = htobe32(V_FW_EQ_ETH_CMD_FBMIN(X_FETCHBURSTMIN_64B) | V_FW_EQ_ETH_CMD_FBMAX(X_FETCHBURSTMAX_512B) | V_FW_EQ_ETH_CMD_EQSIZE(len / EQ_ESIZE)); c.eqaddr = htobe64(nm_txq->ba); rc = -t4_wr_mbox(sc, sc->mbox, &c, sizeof(c), &c); if (rc != 0) { device_printf(pi->dev, "failed to create netmap egress queue: %d\n", rc); return (rc); } nm_txq->cntxt_id = G_FW_EQ_ETH_CMD_EQID(be32toh(c.eqid_pkd)); cntxt_id = nm_txq->cntxt_id - sc->sge.eq_start; if (cntxt_id >= sc->sge.neq) panic("%s: nm_txq->cntxt_id (%d) more than the max (%d)", __func__, cntxt_id, sc->sge.neq - 1); sc->sge.eqmap[cntxt_id] = (void *)nm_txq; nm_txq->pidx = nm_txq->cidx = 0; MPASS(nm_txq->sidx == na->num_tx_desc); nm_txq->equiqidx = nm_txq-> equeqidx = nm_txq->dbidx = 0; nm_txq->doorbells = sc->doorbells; if (isset(&nm_txq->doorbells, DOORBELL_UDB) || isset(&nm_txq->doorbells, DOORBELL_UDBWC) || isset(&nm_txq->doorbells, DOORBELL_WCWR)) { uint32_t s_qpp = sc->sge.eq_s_qpp; uint32_t mask = (1 << s_qpp) - 1; volatile uint8_t *udb; udb = sc->udbs_base + UDBS_DB_OFFSET; udb += (nm_txq->cntxt_id >> s_qpp) << PAGE_SHIFT; nm_txq->udb_qid = nm_txq->cntxt_id & mask; if (nm_txq->udb_qid >= PAGE_SIZE / UDBS_SEG_SIZE) clrbit(&nm_txq->doorbells, DOORBELL_WCWR); else { udb += nm_txq->udb_qid << UDBS_SEG_SHIFT; nm_txq->udb_qid = 0; } nm_txq->udb = (volatile void *)udb; }
/* * Old Format: * sector 0: LIF volume header (40 bytes) * sector 1: <unused> * sector 2: LIF directory (8 x 32 == 256 bytes) * sector 3-: LIF file 0, LIF file 1, etc. * where sectors are 256 bytes. * * New Format: * sector 0: LIF volume header (40 bytes) * sector 1: <unused> * sector 2: LIF directory (8 x 32 == 256 bytes) * sector 3: <unused> * sector 4-31: disklabel (~300 bytes right now) * sector 32-: LIF file 0, LIF file 1, etc. */ int main(int argc, char **argv) { char *n1, *n2, *n3; int n, to; int count; --argc; ++argv; if (argc == 0) usage(); if (!strcmp(argv[0], "-l")) { argv++; argc--; if (argc == 0) usage(); sscanf(argv[0], "0x%x", &loadpoint); lpflag++; argv++; argc--; } if (!lpflag || argc == 0) usage(); n1 = argv[0]; argv++; argc--; if (argc == 0) usage(); if (argc > 1) { n2 = argv[0]; argv++; argc--; if (argc > 1) { n3 = argv[0]; argv++; argc--; } else n3 = NULL; } else n2 = n3 = NULL; to = open(argv[0], O_WRONLY | O_TRUNC | O_CREAT, 0644); if (to < 0) { perror("open"); exit(1); } /* clear possibly unused directory entries */ strncpy(lifd[1].dir_name, " ", 10); lifd[1].dir_type = htobe16(-1); lifd[1].dir_addr = htobe32(0); lifd[1].dir_length = htobe32(0); lifd[1].dir_flag = htobe16(0xFF); lifd[1].dir_exec = htobe32(0); lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1]; /* record volume info */ lifv.vol_id = htobe16(VOL_ID); strncpy(lifv.vol_label, "BOOT43", 6); lifv.vol_addr = htobe32(btolifs(LIF_DIRSTART)); lifv.vol_oct = htobe16(VOL_OCT); lifv.vol_dirsize = htobe32(btolifs(LIF_DIRSIZE)); lifv.vol_version = htobe16(1); /* output bootfile one */ lseek(to, LIF_FILESTART, SEEK_SET); count = putfile(n1, to); n = btolifs(count); strcpy(lifd[0].dir_name, lifname(n1)); lifd[0].dir_type = htobe16(DIR_TYPE); lifd[0].dir_addr = htobe32(btolifs(LIF_FILESTART)); lifd[0].dir_length = htobe32(n); bcddate(n1, lifd[0].dir_toc); lifd[0].dir_flag = htobe16(DIR_FLAG); lifd[0].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[0].dir_addr) + be32toh(lifd[0].dir_length)); /* if there is an optional second boot program, output it */ if (n2) { lseek(to, LIF_FILESTART+lifstob(n), SEEK_SET); count = putfile(n2, to); n = btolifs(count); strcpy(lifd[1].dir_name, lifname(n2)); lifd[1].dir_type = htobe16(DIR_TYPE); lifd[1].dir_addr = htobe32(lifv.vol_length); lifd[1].dir_length = htobe32(n); bcddate(n2, lifd[1].dir_toc); lifd[1].dir_flag = htobe16(DIR_FLAG); lifd[1].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[1].dir_addr) + be32toh(lifd[1].dir_length)); } /* ditto for three */ if (n3) { lseek(to, LIF_FILESTART+lifstob(lifd[0].dir_length+n), SEEK_SET); count = putfile(n3, to); n = btolifs(count); strcpy(lifd[2].dir_name, lifname(n3)); lifd[2].dir_type = htobe16(DIR_TYPE); lifd[2].dir_addr = htobe32(lifv.vol_length); lifd[2].dir_length = htobe32(n); bcddate(n3, lifd[2].dir_toc); lifd[2].dir_flag = htobe16(DIR_FLAG); lifd[2].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[2].dir_addr) + be32toh(lifd[2].dir_length)); } /* output volume/directory header info */ lseek(to, LIF_VOLSTART, SEEK_SET); write(to, &lifv, LIF_VOLSIZE); lseek(to, LIF_DIRSTART, SEEK_SET); write(to, lifd, LIF_DIRSIZE); exit(0); }
int read_dungeon(dungeon_t *d, char *file) { char semantic[6]; uint32_t be32; FILE *f; char *home; size_t len; char *filename; struct stat buf; if (!file) { if (!(home = getenv("HOME"))) { fprintf(stderr, "\"HOME\" is undefined. Using working directory.\n"); home = (char *) "."; } len = (strlen(home) + strlen(SAVE_DIR) + strlen(DUNGEON_SAVE_FILE) + 1 /* The NULL terminator */ + 2 /* The slashes */); filename = (char *) malloc(len * sizeof (*filename)); sprintf(filename, "%s/%s/%s", home, SAVE_DIR, DUNGEON_SAVE_FILE); if (!(f = fopen(filename, "r"))) { perror(filename); free(filename); exit(-1); } if (stat(filename, &buf)) { perror(filename); exit(-1); } free(filename); } else { if (!(f = fopen(file, "r"))) { perror(file); exit(-1); } if (stat(file, &buf)) { perror(file); exit(-1); } } d->num_rooms = 0; fread(semantic, sizeof(semantic), 1, f); semantic[6] = '\0'; if (strncmp(semantic, DUNGEON_SAVE_SEMANTIC, 6)) { fprintf(stderr, "Not an RLG327 save file.\n"); exit(-1); } fread(&be32, sizeof (be32), 1, f); if (be32toh(be32) != 0) { /* Since we expect zero, be32toh() is a no-op. */ fprintf(stderr, "File version mismatch.\n"); exit(-1); } fread(&be32, sizeof (be32), 1, f); if (buf.st_size != be32toh(be32)) { fprintf(stderr, "File size mismatch.\n"); exit(-1); } read_dungeon_map(d, f); d->num_rooms = calculate_num_rooms(buf.st_size); d->rooms = (room_t *) malloc(sizeof (*d->rooms) * d->num_rooms); read_rooms(d, f); fclose(f); return 0; }
static int handle_ddp_data(struct toepcb *toep, __be32 ddp_report, __be32 rcv_nxt, int len) { uint32_t report = be32toh(ddp_report); unsigned int db_flag; struct inpcb *inp = toep->inp; struct tcpcb *tp; struct socket *so; struct sockbuf *sb; struct mbuf *m; db_flag = report & F_DDP_BUF_IDX ? DDP_BUF1_ACTIVE : DDP_BUF0_ACTIVE; if (__predict_false(!(report & F_DDP_INV))) CXGBE_UNIMPLEMENTED("DDP buffer still valid"); INP_WLOCK(inp); so = inp_inpcbtosocket(inp); sb = &so->so_rcv; if (__predict_false(inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT))) { /* * XXX: think a bit more. * tcpcb probably gone, but socket should still be around * because we always wait for DDP completion in soreceive no * matter what. Just wake it up and let it clean up. */ CTR5(KTR_CXGBE, "%s: tid %u, seq 0x%x, len %d, inp_flags 0x%x", __func__, toep->tid, be32toh(rcv_nxt), len, inp->inp_flags); SOCKBUF_LOCK(sb); goto wakeup; } tp = intotcpcb(inp); len += be32toh(rcv_nxt) - tp->rcv_nxt; tp->rcv_nxt += len; tp->t_rcvtime = ticks; #ifndef USE_DDP_RX_FLOW_CONTROL KASSERT(tp->rcv_wnd >= len, ("%s: negative window size", __func__)); tp->rcv_wnd -= len; #endif m = get_ddp_mbuf(len); SOCKBUF_LOCK(sb); if (report & F_DDP_BUF_COMPLETE) toep->ddp_score = DDP_HIGH_SCORE; else discourage_ddp(toep); /* receive buffer autosize */ if (sb->sb_flags & SB_AUTOSIZE && V_tcp_do_autorcvbuf && sb->sb_hiwat < V_tcp_autorcvbuf_max && len > (sbspace(sb) / 8 * 7)) { unsigned int hiwat = sb->sb_hiwat; unsigned int newsize = min(hiwat + V_tcp_autorcvbuf_inc, V_tcp_autorcvbuf_max); if (!sbreserve_locked(sb, newsize, so, NULL)) sb->sb_flags &= ~SB_AUTOSIZE; else toep->rx_credits += newsize - hiwat; } KASSERT(toep->sb_cc >= sbused(sb), ("%s: sb %p has more data (%d) than last time (%d).", __func__, sb, sbused(sb), toep->sb_cc)); toep->rx_credits += toep->sb_cc - sbused(sb); #ifdef USE_DDP_RX_FLOW_CONTROL toep->rx_credits -= len; /* adjust for F_RX_FC_DDP */ #endif sbappendstream_locked(sb, m, 0); toep->sb_cc = sbused(sb); wakeup: KASSERT(toep->ddp_flags & db_flag, ("%s: DDP buffer not active. toep %p, ddp_flags 0x%x, report 0x%x", __func__, toep, toep->ddp_flags, report)); toep->ddp_flags &= ~db_flag; sorwakeup_locked(so); SOCKBUF_UNLOCK_ASSERT(sb); INP_WUNLOCK(inp); return (0); }
static void print_ntp_status_info(NTPStatusInfo *i) { char ts[FORMAT_TIMESPAN_MAX], tmin[FORMAT_TIMESPAN_MAX], tmax[FORMAT_TIMESPAN_MAX]; usec_t delay, t14, t23, offset, root_distance; bool offset_sign; assert(i); /* * "Timestamp Name ID When Generated * ------------------------------------------------------------ * Originate Timestamp T1 time request sent by client * Receive Timestamp T2 time request received by server * Transmit Timestamp T3 time reply sent by server * Destination Timestamp T4 time reply received by client * * The round-trip delay, d, and system clock offset, t, are defined as: * d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2" */ printf(" Server: %s (%s)\n", i->server_address, i->server_name); printf("Poll interval: %s (min: %s; max %s)\n", format_timespan(ts, sizeof(ts), i->poll_interval, 0), format_timespan(tmin, sizeof(tmin), i->poll_min, 0), format_timespan(tmax, sizeof(tmax), i->poll_max, 0)); if (i->packet_count == 0) { printf(" Packet count: 0\n"); return; } if (i->dest < i->origin || i->trans < i->recv || i->dest - i->origin < i->trans - i->recv) { log_error("Invalid NTP response"); return; } delay = (i->dest - i->origin) - (i->trans - i->recv); t14 = i->origin + i->dest; t23 = i->recv + i->trans; offset_sign = t14 < t23; offset = (offset_sign ? t23 - t14 : t14 - t23) / 2; root_distance = i->root_delay / 2 + i->root_dispersion; printf(" Leap: %s\n" " Version: %" PRIu32 "\n" " Stratum: %" PRIu32 "\n", ntp_leap_to_string(i->leap), i->version, i->stratum); if (i->stratum <= 1) printf(" Reference: %s\n", i->reference.str); else printf(" Reference: %" PRIX32 "\n", be32toh(i->reference.val)); printf(" Precision: %s (%" PRIi32 ")\n", format_timespan(ts, sizeof(ts), DIV_ROUND_UP((nsec_t) (exp2(i->precision) * NSEC_PER_SEC), NSEC_PER_USEC), 0), i->precision); printf("Root distance: %s (max: %s)\n", format_timespan(ts, sizeof(ts), root_distance, 0), format_timespan(tmax, sizeof(tmax), i->root_distance_max, 0)); printf(" Offset: %s%s\n", offset_sign ? "+" : "-", format_timespan(ts, sizeof(ts), offset, 0)); printf(" Delay: %s\n", format_timespan(ts, sizeof(ts), delay, 0)); printf(" Jitter: %s\n", format_timespan(ts, sizeof(ts), i->jitter, 0)); printf(" Packet count: %" PRIu64 "\n", i->packet_count); if (!i->spike) printf(" Frequency: %+.3fppm\n", (double) i->freq / 0x10000); }
static int lgss_sk_validate_cred(struct lgss_cred *cred, gss_buffer_desc *token, gss_buffer_desc *ctx_token) { struct sk_cred *skc = cred->lc_mech_cred; gss_buffer_desc bufs[SK_RESP_BUFFERS]; uint32_t version; int i; uint32_t rc; /* Decode responder buffers and validate */ i = sk_decode_netstring(bufs, SK_RESP_BUFFERS, token); if (i != SK_RESP_BUFFERS) { printerr(0, "Invalid token received\n"); return -EINVAL; } rc = sk_verify_hmac(skc, bufs, SK_RESP_BUFFERS - 1, EVP_sha256(), &bufs[SK_RESP_HMAC]); if (rc != GSS_S_COMPLETE) { printerr(0, "Invalid HMAC receieved: 0x%x\n", rc); return -EINVAL; } if (bufs[SK_RESP_VERSION].length != sizeof(version)) { printerr(0, "Invalid version received (wrong size)\n"); return -EINVAL; } memcpy(&version, bufs[SK_RESP_VERSION].value, sizeof(version)); version = be32toh(version); if (version != SK_MSG_VERSION) { printerr(0, "Invalid version received: %d\n", version); return -EINVAL; } /* In the rare event that both the random values are equal the * client has the responsability to retry the connection attempt * otherwise we would leak information about the plain text by * reuusing IVs as both peer and host use the same values other * than the nonce. */ memcpy(&skc->sc_kctx.skc_peer_random, bufs[SK_RESP_RANDOM].value, sizeof(skc->sc_kctx.skc_peer_random)); if (skc->sc_kctx.skc_host_random == skc->sc_kctx.skc_peer_random) { printerr(0, "Host and peer randoms are equal, must retry to " "ensure unique value for nonce\n"); return -EAGAIN; } rc = sk_compute_dh_key(skc, &bufs[SK_RESP_PUB_KEY]); if (rc == GSS_S_DEFECTIVE_TOKEN) { /* Defective token for short key means we need to retry * because there is a chance that the parameters generated * resulted in a key that is 1 byte short */ printerr(0, "Short key computed, must retry\n"); return -EAGAIN; } else if (rc != GSS_S_COMPLETE) { printerr(0, "Failed to compute session key: 0x%x\n", rc); return -EINVAL; } rc = sk_session_kdf(skc, cred->lc_self_nid, &cred->lc_mech_token, token); if (rc) { printerr(0, "Failed to calulate derived key\n"); return -EINVAL; } rc = sk_compute_keys(skc); if (rc) { printerr(0, "Failed to compute HMAC and session key\n"); return -EINVAL; } if (sk_serialize_kctx(skc, ctx_token)) { printerr(0, "Failed to serialize context for kernel\n"); return -EINVAL; } return 0; }
static int print_timesync_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) { char type; const char *contents; int r; assert(name); assert(m); r = sd_bus_message_peek_type(m, &type, &contents); if (r < 0) return r; switch (type) { case SD_BUS_TYPE_STRUCT: if (streq(name, "NTPMessage")) { _cleanup_(ntp_status_info_clear) NTPStatusInfo i = {}; char ts[FORMAT_TIMESPAN_MAX], stamp[FORMAT_TIMESTAMP_MAX]; r = map_ntp_message(NULL, NULL, m, NULL, &i); if (r < 0) return r; if (i.packet_count == 0) return 1; if (!value) { fputs(name, stdout); fputc('=', stdout); } printf("{ Leap=%u, Version=%u, Mode=%u, Stratum=%u, Precision=%i,", i.leap, i.version, i.mode, i.stratum, i.precision); printf(" RootDelay=%s,", format_timespan(ts, sizeof(ts), i.root_delay, 0)); printf(" RootDispersion=%s,", format_timespan(ts, sizeof(ts), i.root_dispersion, 0)); if (i.stratum == 1) printf(" Reference=%s,", i.reference.str); else printf(" Reference=%" PRIX32 ",", be32toh(i.reference.val)); printf(" OriginateTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.origin)); printf(" ReceiveTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.recv)); printf(" TransmitTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.trans)); printf(" DestinationTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.dest)); printf(" Ignored=%s PacketCount=%" PRIu64 ",", yes_no(i.spike), i.packet_count); printf(" Jitter=%s }\n", format_timespan(ts, sizeof(ts), i.jitter, 0)); return 1; } else if (streq(name, "ServerAddress")) { _cleanup_free_ char *str = NULL; r = map_server_address(NULL, NULL, m, NULL, &str); if (r < 0) return r; if (arg_all || !isempty(str)) bus_print_property_value(name, expected_value, value, str); return 1; } break; } return 0; }
int digita_serial_open(CameraPrivateLibrary *dev, Camera *camera) { GPPortSettings settings; int selected_speed; int ret, retries, negotiated = 0; unsigned char buffer[20]; unsigned short s; unsigned int l; /* Get the settings */ ret = gp_port_get_settings(camera->port, &settings); if (ret < 0) return ret; /* Remember the selected speed */ selected_speed = settings.serial.speed; if (!selected_speed) selected_speed = 115200; /* Try the maximum speed */ /* Set the settings */ settings.serial.speed = 9600; settings.serial.bits = 8; settings.serial.parity = 0; settings.serial.stopbits = 1; ret = gp_port_set_settings(camera->port, settings); if (ret < 0) return ret; dev->send = digita_serial_send; dev->read = digita_serial_read; gp_port_send_break(dev->gpdev, 4); usleep(10000); /* FIXME: In some situations we may want to try a slower speed */ for (retries = 0; !negotiated && retries < MAX_BEACON_RETRIES; retries++) { unsigned char csum; int i, timeouts = 0; /* * Read the beacon */ memset(buffer, 0, sizeof(buffer)); for (i = 0; (i < BEACON_LEN * 2) && (timeouts < MAX_BEACON_TIMEOUTS); i++) { /* We specifically eat as much as we can to catch any */ /* garbage before or after */ ret = gp_port_read(dev->gpdev, (void *)buffer, 1); if (ret < 0) { GP_DEBUG("couldn't read beacon (ret = %d)", ret); timeouts++; continue; } if (buffer[0] == 0xA5) break; } if (timeouts >= MAX_BEACON_TIMEOUTS) continue; ret = gp_port_read(dev->gpdev, (void *)(buffer + 1), BEACON_LEN - 1); if (ret < 0) { GP_DEBUG("couldn't read beacon (ret = %d)", ret); continue; } if (buffer[0] != 0xA5 || buffer[1] != 0x5A) { GP_DEBUG("Invalid header for beacon 0x%02x 0x%02x", buffer[0], buffer[1]); continue; } csum = buffer[6]; buffer[6] = 0; if (checksum(buffer, BEACON_LEN) != csum) { GP_DEBUG("Beacon checksum failed (calculated 0x%02x, received 0x%02x)", checksum(buffer, BEACON_LEN), csum); continue; } memcpy((void *)&s, &buffer[2], 2); GP_DEBUG("Vendor: 0x%04x", be16toh(s)); memcpy((void *)&s, &buffer[4], 2); GP_DEBUG("Product: 0x%04x", be16toh(s)); /* * Send the beacon acknowledgement */ buffer[0] = 0x5A; /* Magic */ buffer[1] = 0xA5; buffer[2] = 0x55; /* I/F Type */ buffer[3] = 0; /* Comm Flag */ l = htobe32(selected_speed); memcpy(&buffer[4], (void *)&l, 4); /* Data speed */ s = htobe16(1023); memcpy(&buffer[8], (void *)&s, 2); /* Device Frame Size */ s = htobe16(1023); memcpy(&buffer[10], (void *)&s, 2); /* Host Frame Size */ buffer[12] = 0; buffer[12] = checksum(buffer, BEACON_ACK_LENGTH); ret = gp_port_write(dev->gpdev, (void *)buffer, BEACON_ACK_LENGTH); if (ret < 0) { GP_DEBUG("couldn't write beacon (ret = %d)", ret); return -1; } /* * Read the beacon completion */ ret = gp_port_read(dev->gpdev, (void *)buffer, BEACON_COMP_LENGTH); if (ret < 0) { GP_DEBUG("couldn't read beacon_comp (ret = %d)", ret); continue; } if ((signed char)buffer[0] < 0) { GP_DEBUG("Bad status %d during beacon completion", (signed int)buffer[0]); continue; } memcpy((void *)&s, &buffer[6], sizeof(s)); dev->deviceframesize = be16toh(s); memcpy((void *)&l, &buffer[2], sizeof(l)); GP_DEBUG("negotiated %d", be32toh(l)); settings.serial.speed = be32toh(l); usleep(100000); /* Wait before */ ret = gp_port_set_settings(dev->gpdev, settings); if (ret < 0) return ret; usleep(100000); /* Wait after */ /* * The host interface spec mentions kTestSerialData, but * doesn't elaborate anywhere else on it. So, I guess we * assume everything is working here */ negotiated = 1; } return negotiated ? 0 : -1; }
static int test_advertise_option(sd_event *e) { _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; DHCP6Message *advertise = (DHCP6Message *)msg_advertise; uint8_t *optval, *opt = msg_advertise + sizeof(DHCP6Message); uint16_t optcode; size_t optlen, len = sizeof(msg_advertise) - sizeof(DHCP6Message); be32_t val; uint8_t preference = 255; struct in6_addr addr; uint32_t lt_pref, lt_valid; int r; bool opt_clientid = false; struct in6_addr *addrs; char **domains; if (verbose) printf("* %s\n", __FUNCTION__); assert_se(dhcp6_lease_new(&lease) >= 0); assert_se(advertise->type == DHCP6_ADVERTISE); assert_se((be32toh(advertise->transaction_id) & 0x00ffffff) == 0x0fb4e5); while ((r = dhcp6_option_parse(&opt, &len, &optcode, &optlen, &optval)) >= 0) { switch(optcode) { case SD_DHCP6_OPTION_CLIENTID: assert_se(optlen == 14); opt_clientid = true; break; case SD_DHCP6_OPTION_IA_NA: assert_se(optlen == 94); assert_se(!memcmp(optval, &msg_advertise[26], optlen)); val = htobe32(0x0ecfa37d); assert_se(!memcmp(optval, &val, sizeof(val))); val = htobe32(80); assert_se(!memcmp(optval + 4, &val, sizeof(val))); val = htobe32(120); assert_se(!memcmp(optval + 8, &val, sizeof(val))); assert_se(dhcp6_option_parse_ia(&optval, &optlen, optcode, &lease->ia) >= 0); break; case SD_DHCP6_OPTION_SERVERID: assert_se(optlen == 14); assert_se(!memcmp(optval, &msg_advertise[179], optlen)); assert_se(dhcp6_lease_set_serverid(lease, optval, optlen) >= 0); break; case SD_DHCP6_OPTION_PREFERENCE: assert_se(optlen == 1); assert_se(!*optval); assert_se(dhcp6_lease_set_preference(lease, *optval) >= 0); break; case SD_DHCP6_OPTION_ELAPSED_TIME: assert_se(optlen == 2); break; case SD_DHCP6_OPTION_DNS_SERVERS: assert_se(optlen == 16); assert_se(dhcp6_lease_set_dns(lease, optval, optlen) >= 0); break; case SD_DHCP6_OPTION_DOMAIN_LIST: assert_se(optlen == 11); assert_se(dhcp6_lease_set_domains(lease, optval, optlen) >= 0); break; case SD_DHCP6_OPTION_SNTP_SERVERS: assert_se(optlen == 16); assert_se(dhcp6_lease_set_sntp(lease, optval, optlen) >= 0); break; default: break; } } assert_se(r == -ENOMSG); assert_se(opt_clientid); sd_dhcp6_lease_reset_address_iter(lease); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) >= 0); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(lt_pref == 150); assert_se(lt_valid == 180); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) == -ENOMSG); sd_dhcp6_lease_reset_address_iter(lease); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) >= 0); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) == -ENOMSG); sd_dhcp6_lease_reset_address_iter(lease); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) >= 0); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(sd_dhcp6_lease_get_address(lease, &addr, <_pref, <_valid) == -ENOMSG); assert_se(dhcp6_lease_get_serverid(lease, &opt, &len) >= 0); assert_se(len == 14); assert_se(!memcmp(opt, &msg_advertise[179], len)); assert_se(dhcp6_lease_get_preference(lease, &preference) >= 0); assert_se(preference == 0); r = sd_dhcp6_lease_get_dns(lease, &addrs); assert_se(r == 1); assert_se(!memcmp(addrs, &msg_advertise[124], r * 16)); r = sd_dhcp6_lease_get_domains(lease, &domains); assert_se(r == 1); assert_se(!strcmp("lab.intra", domains[0])); assert_se(domains[1] == NULL); r = sd_dhcp6_lease_get_ntp_addrs(lease, &addrs); assert_se(r == 1); assert_se(!memcmp(addrs, &msg_advertise[159], r * 16)); return 0; }
/* * Note - these are rounded up to 128 bytes; but we * only use 96 bytes from it. */ static void ar9300_decode_txdesc(struct if_ath_alq_payload *a) { struct ar9300_txc txc; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txc, &a->payload, 96); printf("[%u.%06u] [%llu] TXD\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid)); printf(" DescLen=%d, TxQcuNum=%d, CtrlStat=%d, DescId=0x%04x\n", txc.ds_info & 0xff, MS(txc.ds_info, AR_tx_qcu_num), MS(txc.ds_info, AR_ctrl_stat), MS(txc.ds_info, AR_desc_id)); /* link */ printf(" Link 0x%08x\n", txc.ds_link); /* data0 */ printf(" Data0 0x%08x Len %d\n", txc.ds_data0, MS(txc.ds_ctl3, AR_buf_len)); /* data1 */ printf(" Data1 0x%08x Len %d\n", txc.ds_data1, MS(txc.ds_ctl5, AR_buf_len)); /* data2 */ printf(" Data2 0x%08x Len %d\n", txc.ds_data2, MS(txc.ds_ctl7, AR_buf_len)); /* data3 */ printf(" Data3 0x%08x Len %d\n", txc.ds_data3, MS(txc.ds_ctl9, AR_buf_len)); /* ctl10 */ printf(" Desc ID=0x%04x, Chksum=0x%04x (ctl10=0x%08x)\n", MS(txc.ds_ctl10, AR_tx_desc_id), txc.ds_ctl10 & AR_tx_ptr_chk_sum, txc.ds_ctl10); /* ctl11 */ printf(" Frame Len=%d, VMF=%d, LowRxChain=%d, TxClrRetry=%d\n", txc.ds_ctl11 & AR_frame_len, MF(txc.ds_ctl11, AR_virt_more_frag), MF(txc.ds_ctl11, AR_low_rx_chain), MF(txc.ds_ctl11, AR_tx_clear_retry)); printf(" TX power 0 = %d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n", MS(txc.ds_ctl11, AR_xmit_power0), MF(txc.ds_ctl11, AR_rts_enable), MF(txc.ds_ctl11, AR_veol), MF(txc.ds_ctl11, AR_clr_dest_mask)); printf(" TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n", MF(txc.ds_ctl11, AR_tx_intr_req), MF(txc.ds_ctl11, AR_dest_idx_valid), MF(txc.ds_ctl11, AR_cts_enable)); /* ctl12 */ printf(" Paprd Chain Mask=0x%x, TxMore=%d, DestIdx=%d," " FrType=0x%x\n", MS(txc.ds_ctl12, AR_paprd_chain_mask), MF(txc.ds_ctl12, AR_tx_more), MS(txc.ds_ctl12, AR_dest_idx), MS(txc.ds_ctl12, AR_frame_type)); printf(" NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d," " ExtAndCtl=%d\n", MF(txc.ds_ctl12, AR_no_ack), MF(txc.ds_ctl12, AR_insert_ts), MF(txc.ds_ctl12, AR_corrupt_fcs), MF(txc.ds_ctl12, AR_ext_only), MF(txc.ds_ctl12, AR_ext_and_ctl)); printf(" IsAggr=%d, MoreRifs=%d, LocMode=%d\n", MF(txc.ds_ctl12, AR_is_aggr), MF(txc.ds_ctl12, AR_more_rifs), MF(txc.ds_ctl12, AR_loc_mode)); /* ctl13 */ printf(" DurUpEna=%d, Burstdur=0x%04x\n", MF(txc.ds_ctl13, AR_dur_update_ena), MS(txc.ds_ctl13, AR_burst_dur)); printf(" Try0=%d, Try1=%d, Try2=%d, Try3=%d\n", MS(txc.ds_ctl13, AR_xmit_data_tries0), MS(txc.ds_ctl13, AR_xmit_data_tries1), MS(txc.ds_ctl13, AR_xmit_data_tries2), MS(txc.ds_ctl13, AR_xmit_data_tries3)); /* ctl14 */ printf(" rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n", MS(txc.ds_ctl14, AR_xmit_rate0), MS(txc.ds_ctl14, AR_xmit_rate1), MS(txc.ds_ctl14, AR_xmit_rate2), MS(txc.ds_ctl14, AR_xmit_rate3)); /* ctl15 */ printf(" try 0: PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl15, AR_packet_dur0), MF(txc.ds_ctl15, AR_rts_cts_qual0)); printf(" try 1: PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl15, AR_packet_dur1), MF(txc.ds_ctl15, AR_rts_cts_qual1)); /* ctl16 */ printf(" try 2: PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl16, AR_packet_dur2), MF(txc.ds_ctl16, AR_rts_cts_qual2)); printf(" try 3: PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl16, AR_packet_dur3), MF(txc.ds_ctl16, AR_rts_cts_qual3)); /* ctl17 */ printf(" AggrLen=%d, PadDelim=%d, EncrType=%d, TxDcApStaSel=%d\n", MS(txc.ds_ctl17, AR_aggr_len), MS(txc.ds_ctl17, AR_pad_delim), MS(txc.ds_ctl17, AR_encr_type), MF(txc.ds_ctl17, AR_tx_dc_ap_sta_sel)); printf(" Calib=%d LDPC=%d\n", MF(txc.ds_ctl17, AR_calibrating), MF(txc.ds_ctl17, AR_ldpc)); /* ctl18 */ printf(" try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl18, AR_chain_sel0), MF(txc.ds_ctl18, AR_gi0), MF(txc.ds_ctl18, AR_2040_0), MF(txc.ds_ctl18, AR_stbc0)); printf(" try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl18, AR_chain_sel1), MF(txc.ds_ctl18, AR_gi1), MF(txc.ds_ctl18, AR_2040_1), MF(txc.ds_ctl18, AR_stbc1)); printf(" try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl18, AR_chain_sel2), MF(txc.ds_ctl18, AR_gi2), MF(txc.ds_ctl18, AR_2040_2), MF(txc.ds_ctl18, AR_stbc2)); printf(" try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl18, AR_chain_sel3), MF(txc.ds_ctl18, AR_gi3), MF(txc.ds_ctl18, AR_2040_3), MF(txc.ds_ctl18, AR_stbc3)); /* ctl19 */ printf(" NotSounding=%d\n", MF(txc.ds_ctl19, AR_not_sounding)); printf(" try 0: ant=0x%08x, antsel=%d, ness=%d\n", txc.ds_ctl19 & AR_tx_ant0, MF(txc.ds_ctl19, AR_tx_ant_sel0), MS(txc.ds_ctl19, AR_ness)); /* ctl20 */ printf(" try 1: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n", MS(txc.ds_ctl20, AR_xmit_power1), txc.ds_ctl20 & AR_tx_ant1, MF(txc.ds_ctl20, AR_tx_ant_sel1), MS(txc.ds_ctl20, AR_ness1)); /* ctl21 */ printf(" try 2: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n", MS(txc.ds_ctl21, AR_xmit_power2), txc.ds_ctl21 & AR_tx_ant2, MF(txc.ds_ctl21, AR_tx_ant_sel2), MS(txc.ds_ctl21, AR_ness2)); /* ctl22 */ printf(" try 3: TxPower=%d, ant=0x%08x, antsel=%d, ness=%d\n", MS(txc.ds_ctl22, AR_xmit_power3), txc.ds_ctl22 & AR_tx_ant3, MF(txc.ds_ctl22, AR_tx_ant_sel3), MS(txc.ds_ctl22, AR_ness3)); printf("\n ------ \n"); }
int cRequestPacket::serverError() { if ((packetPos == 0) && (userDataLength == 4) && !be32toh(*(uint32_t*)userData)) return 1; else return 0; }
int mrp_fragbuf_pull(mrp_fragbuf_t *buf, void **datap, size_t *sizep) { void *data; uint32_t size; if (buf == NULL || buf->used <= 0) return FALSE; if (MRP_UNLIKELY(*datap && (*datap < buf->data || *datap > buf->data + buf->used))) { mrp_log_warning("%s(): *** looks like we're called with an unreset " "datap pointer... ***", __FUNCTION__); } /* start of iteration */ if (*datap == NULL) { if (!buf->framed) { *datap = buf->data; *sizep = buf->used; return TRUE; } else { if (buf->used < (int)sizeof(size)) return FALSE; size = be32toh(*(uint32_t *)buf->data); if (buf->used >= (int)(sizeof(size) + size)) { *datap = buf->data + sizeof(size); *sizep = size; return TRUE; } else return FALSE; } } /* continue iteration */ else { if (!buf->framed) { data = *datap + *sizep; if (buf->data <= data && data < buf->data + buf->used) { memmove(buf->data, data, buf->used - (data - buf->data)); buf->used -= (data - buf->data); *datap = buf->data; *sizep = buf->used; return TRUE; } else { if (data == buf->data + buf->used) buf->used = 0; return FALSE; } } else { if (*datap != buf->data + sizeof(size)) return FALSE; size = be32toh(*(uint32_t *)buf->data); if ((int)(size + sizeof(size)) <= buf->used) { memmove(buf->data, buf->data + size + sizeof(size), buf->used - (size + sizeof(size))); buf->used -= size + sizeof(size); } else return FALSE; if (buf->used <= (int)sizeof(size)) return FALSE; size = be32toh(*(uint32_t *)buf->data); data = buf->data + sizeof(size); if (buf->used >= (int)(size + sizeof(size))) { *datap = data; *sizep = size; return TRUE; } return FALSE; } } }
void hextrace_show(int fd, FILE *fp_out, const char *objdump, const char *machine, const char *guest_objdump, const char *guest_machine, void **sym_tree, enum cov_format cov_fmt, enum trace_format trace_in_fmt, enum trace_format trace_out_fmt) { struct hextracer t; FILE *fp_in; char *line = NULL; size_t len = 0; ssize_t ret; fp_in = fdopen(fd, "r"); if (!fp_in) { fprintf(stderr, "Cant open input file\n"); exit(1); } fprintf(stderr, "Processing hex trace\n"); t.tr.fd = fd; t.tr.fp_out = fp_out; t.tr.sym_tree = sym_tree; t.tr.host.objdump = objdump; t.tr.host.machine = machine; t.tr.guest.objdump = guest_objdump; t.tr.guest.machine = guest_machine; while ((ret = getline(&line, &len, fp_in)) != -1) { uint64_t start; start = strtoull(line, NULL, 16); switch (trace_in_fmt) { case TRACE_ASCII_HEX_LE16: start = le16toh(start); break; case TRACE_ASCII_HEX_LE32: start = le32toh(start); break; case TRACE_ASCII_HEX_LE64: start = le64toh(start); break; case TRACE_ASCII_HEX_BE16: start = be16toh(start); break; case TRACE_ASCII_HEX_BE32: start = be32toh(start); break; case TRACE_ASCII_HEX_BE64: start = be64toh(start); break; case TRACE_ASCII_HEX: default: break; } ht_process_exec(&t, start, start + 4, cov_fmt); } free(line); fprintf(stderr, "done.\n"); }
static void ar5416_decode_txdesc(struct if_ath_alq_payload *a) { struct ar5416_desc txc; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txc, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] TXD\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid)); printf(" link=0x%08x, data=0x%08x\n", txc.ds_link, txc.ds_data); /* ds_ctl0 */ printf(" Frame Len=%d, VMF=%d\n", txc.ds_ctl0 & AR_FrameLen, MF(txc.ds_ctl0, AR_VirtMoreFrag)); printf(" TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n", MS(txc.ds_ctl0, AR_XmitPower), MF(txc.ds_ctl0, AR_RTSEnable), MF(txc.ds_ctl0, AR_VEOL), MF(txc.ds_ctl0, AR_ClrDestMask)); printf(" TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n", MF(txc.ds_ctl0, AR_TxIntrReq), MF(txc.ds_ctl0, AR_DestIdxValid), MF(txc.ds_ctl0, AR_CTSEnable)); /* ds_ctl1 */ printf(" BufLen=%d, TxMore=%d, DestIdx=%d," " FrType=0x%x\n", txc.ds_ctl1 & AR_BufLen, MF(txc.ds_ctl1, AR_TxMore), MS(txc.ds_ctl1, AR_DestIdx), MS(txc.ds_ctl1, AR_FrameType)); printf(" NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d," " ExtAndCtl=%d\n", MF(txc.ds_ctl1, AR_NoAck), MF(txc.ds_ctl1, AR_InsertTS), MF(txc.ds_ctl1, AR_CorruptFCS), MF(txc.ds_ctl1, AR_ExtOnly), MF(txc.ds_ctl1, AR_ExtAndCtl)); printf(" MoreAggr=%d, IsAggr=%d, MoreRifs=%d\n", MF(txc.ds_ctl1, AR_MoreAggr), MF(txc.ds_ctl1, AR_IsAggr), MF(txc.ds_ctl1, AR_MoreRifs)); /* ds_ctl2 */ printf(" DurUpEna=%d, Burstdur=0x%04x\n", MF(txc.ds_ctl2, AR_DurUpdateEn), MS(txc.ds_ctl2, AR_BurstDur)); printf(" Try0=%d, Try1=%d, Try2=%d, Try3=%d\n", MS(txc.ds_ctl2, AR_XmitDataTries0), MS(txc.ds_ctl2, AR_XmitDataTries1), MS(txc.ds_ctl2, AR_XmitDataTries2), MS(txc.ds_ctl2, AR_XmitDataTries3)); /* ds_ctl3, 4 */ printf(" try 0: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate0), MS(txc.ds_ctl4, AR_PacketDur0), MF(txc.ds_ctl4, AR_RTSCTSQual0)); printf(" try 1: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate1), MS(txc.ds_ctl4, AR_PacketDur1), MF(txc.ds_ctl4, AR_RTSCTSQual1)); /* ds_ctl3, 5 */ printf(" try 2: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate2), MS(txc.ds_ctl5, AR_PacketDur2), MF(txc.ds_ctl5, AR_RTSCTSQual2)); printf(" try 3: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate3), MS(txc.ds_ctl5, AR_PacketDur3), MF(txc.ds_ctl5, AR_RTSCTSQual3)); /* ds_ctl6 */ printf(" AggrLen=%d, PadDelim=%d, EncrType=%d\n", MS(txc.ds_ctl6, AR_AggrLen), MS(txc.ds_ctl6, AR_PadDelim), MS(txc.ds_ctl6, AR_EncrType)); /* ds_ctl7 */ printf(" try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel0), MF(txc.ds_ctl7, AR_GI0), MF(txc.ds_ctl7, AR_2040_0), MF(txc.ds_ctl7, AR_STBC0)); printf(" try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel1), MF(txc.ds_ctl7, AR_GI1), MF(txc.ds_ctl7, AR_2040_1), MF(txc.ds_ctl7, AR_STBC1)); printf(" try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel2), MF(txc.ds_ctl7, AR_GI2), MF(txc.ds_ctl7, AR_2040_2), MF(txc.ds_ctl7, AR_STBC2)); printf(" try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel3), MF(txc.ds_ctl7, AR_GI3), MF(txc.ds_ctl7, AR_2040_3), MF(txc.ds_ctl7, AR_STBC3)); printf(" RTSCtsRate=0x%02x\n", MS(txc.ds_ctl7, AR_RTSCTSRate)); /* ds_ctl8 */ printf(" try 0: ant=0x%08x\n", txc.ds_ctl8 & AR_AntCtl0); /* ds_ctl9 */ printf(" try 1: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl9, AR_XmitPower1), txc.ds_ctl9 & AR_AntCtl1); /* ds_ctl10 */ printf(" try 2: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl10, AR_XmitPower2), txc.ds_ctl10 & AR_AntCtl2); /* ds_ctl11 */ printf(" try 3: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl11, AR_XmitPower3), txc.ds_ctl11 & AR_AntCtl3); printf("\n ------ \n"); }
int lttng_live_establish_connection(struct lttng_live_ctx *ctx) { struct lttng_viewer_cmd cmd; struct lttng_viewer_connect connect; int ret; ssize_t ret_len; if (lttng_live_should_quit()) { ret = -1; goto end; } cmd.cmd = htobe32(LTTNG_VIEWER_CONNECT); cmd.data_size = htobe64((uint64_t) sizeof(connect)); cmd.cmd_version = htobe32(0); connect.viewer_session_id = -1ULL; /* will be set on recv */ connect.major = htobe32(LTTNG_LIVE_MAJOR); connect.minor = htobe32(LTTNG_LIVE_MINOR); connect.type = htobe32(LTTNG_VIEWER_CLIENT_COMMAND); ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd)); if (ret_len < 0) { perror("[error] Error sending cmd"); goto error; } assert(ret_len == sizeof(cmd)); ret_len = lttng_live_send(ctx->control_sock, &connect, sizeof(connect)); if (ret_len < 0) { perror("[error] Error sending version"); goto error; } assert(ret_len == sizeof(connect)); ret_len = lttng_live_recv(ctx->control_sock, &connect, sizeof(connect)); if (ret_len == 0) { fprintf(stderr, "[error] Remote side has closed connection\n"); goto error; } if (ret_len < 0) { perror("[error] Error receiving version"); goto error; } assert(ret_len == sizeof(connect)); printf_verbose("Received viewer session ID : %" PRIu64 "\n", be64toh(connect.viewer_session_id)); printf_verbose("Relayd version : %u.%u\n", be32toh(connect.major), be32toh(connect.minor)); if (LTTNG_LIVE_MAJOR != be32toh(connect.major)) { fprintf(stderr, "[error] Incompatible lttng-relayd protocol\n"); goto error; } /* Use the smallest protocol version implemented. */ if (LTTNG_LIVE_MINOR > be32toh(connect.minor)) { ctx->minor = be32toh(connect.minor); } else { ctx->minor = LTTNG_LIVE_MINOR; } ctx->major = LTTNG_LIVE_MAJOR; ret = 0; end: return ret; error: fprintf(stderr, "[error] Unable to establish connection\n"); return -1; }
static void ar5416_decode_txstatus(struct if_ath_alq_payload *a) { struct ar5416_desc txs; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txs, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] TXSTATUS: TxDone=%d, FrmOk=%d, filt=%d, TS=0x%08x\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid), MF(txs.u.tx.status[9], AR_TxDone), MF(txs.u.tx.status[1], AR_FrmXmitOK), MF(txs.u.tx.status[1], AR_Filtered), txs.u.tx.status[2]); /* ds_txstatus0 */ printf(" RX RSSI 0 [%d %d %d]", MS(txs.u.tx.status[0], AR_TxRSSIAnt00), MS(txs.u.tx.status[0], AR_TxRSSIAnt01), MS(txs.u.tx.status[0], AR_TxRSSIAnt02)); /* ds_txstatus5 */ printf(" RX RSSI 1 [%d %d %d] Comb=%d\n", MS(txs.u.tx.status[5], AR_TxRSSIAnt10), MS(txs.u.tx.status[5], AR_TxRSSIAnt11), MS(txs.u.tx.status[5], AR_TxRSSIAnt12), MS(txs.u.tx.status[5], AR_TxRSSICombined)); /* ds_txstatus0 */ printf(" BA Valid=%d", MF(txs.u.tx.status[0], AR_TxBaStatus)); /* ds_txstatus1 */ printf(", Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n", MF(txs.u.tx.status[1], AR_FrmXmitOK), MF(txs.u.tx.status[1], AR_ExcessiveRetries), MF(txs.u.tx.status[1], AR_FIFOUnderrun), MF(txs.u.tx.status[1], AR_Filtered)); printf(" DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d," " TxTimerExceeded=%d\n", MF(txs.u.tx.status[1], AR_TxDelimUnderrun), MF(txs.u.tx.status[1], AR_TxDataUnderrun), MF(txs.u.tx.status[1], AR_DescCfgErr), MF(txs.u.tx.status[1], AR_TxTimerExpired)); printf(" RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n", MS(txs.u.tx.status[1], AR_RTSFailCnt), MS(txs.u.tx.status[1], AR_DataFailCnt), MS(txs.u.tx.status[1], AR_VirtRetryCnt)); /* ds_txstatus2 */ printf(" TxTimestamp=0x%08x", txs.u.tx.status[2]); /* ds_txstatus3 */ /* ds_txstatus4 */ printf(", BALow=0x%08x", txs.u.tx.status[3]); printf(", BAHigh=0x%08x\n", txs.u.tx.status[4]); /* ds_txstatus6 */ /* ds_txstatus7 */ /* ds_txstatus8 */ printf(" TxEVM[0]=0x%08x, TxEVM[1]=0x%08x, TxEVM[2]=0x%08x\n", txs.u.tx.status[6], txs.u.tx.status[7], txs.u.tx.status[8]); /* ds_txstatus9 */ printf(" TxDone=%d, SeqNum=0x%04x, TxOpExceeded=%d, FinalTsIdx=%d\n", MF(txs.u.tx.status[9], AR_TxDone), MS(txs.u.tx.status[9], AR_SeqNum), MF(txs.u.tx.status[9], AR_TxOpExceeded), MS(txs.u.tx.status[9], AR_FinalTxIdx)); printf(" PowerMgmt=%d, TxTid=%d\n", MF(txs.u.tx.status[9], AR_PowerMgmt), MS(txs.u.tx.status[9], AR_TxTid)); printf("\n ------\n"); }
int lttng_live_list_sessions(struct lttng_live_ctx *ctx, const char *path) { struct lttng_viewer_cmd cmd; struct lttng_viewer_list_sessions list; struct lttng_viewer_session lsession; int i, ret, sessions_count, print_list = 0; ssize_t ret_len; uint64_t session_id; GPtrArray *session_list = NULL; if (lttng_live_should_quit()) { ret = -1; goto end; } if (strlen(ctx->session_name) == 0) { print_list = 1; session_list = g_ptr_array_new(); } cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS); cmd.data_size = htobe64((uint64_t) 0); cmd.cmd_version = htobe32(0); ret_len = lttng_live_send(ctx->control_sock, &cmd, sizeof(cmd)); if (ret_len < 0) { perror("[error] Error sending cmd"); goto error; } assert(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(ctx->control_sock, &list, sizeof(list)); if (ret_len == 0) { fprintf(stderr, "[error] Remote side has closed connection\n"); goto error; } if (ret_len < 0) { perror("[error] Error receiving session list"); goto error; } assert(ret_len == sizeof(list)); sessions_count = be32toh(list.sessions_count); for (i = 0; i < sessions_count; i++) { ret_len = lttng_live_recv(ctx->control_sock, &lsession, sizeof(lsession)); if (ret_len == 0) { fprintf(stderr, "[error] Remote side has closed connection\n"); goto error; } if (ret_len < 0) { perror("[error] Error receiving session"); goto error; } assert(ret_len == sizeof(lsession)); lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; session_id = be64toh(lsession.id); if (print_list) { update_session_list(session_list, lsession.hostname, lsession.session_name, be32toh(lsession.streams), be32toh(lsession.clients), be32toh(lsession.live_timer)); } else { if ((strncmp(lsession.session_name, ctx->session_name, MAXNAMLEN) == 0) && (strncmp(lsession.hostname, ctx->traced_hostname, MAXNAMLEN) == 0)) { printf_verbose("Reading from session %" PRIu64 "\n", session_id); g_array_append_val(ctx->session_ids, session_id); } } } if (print_list) { print_session_list(session_list, path); free_session_list(session_list); } ret = 0; end: return ret; error: fprintf(stderr, "[error] Unable to list sessions\n"); return -1; }
static int do_rx_iscsi_ddp(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m) { struct adapter *sc = iq->adapter; struct cxgbei_data *ci = sc->iscsi_ulp_softc; const struct cpl_rx_data_ddp *cpl = (const void *)(rss + 1); u_int tid = GET_TID(cpl); struct toepcb *toep = lookup_tid(sc, tid); struct inpcb *inp = toep->inp; struct socket *so; struct sockbuf *sb; struct tcpcb *tp; struct icl_cxgbei_conn *icc; struct icl_conn *ic; struct icl_cxgbei_pdu *icp = toep->ulpcb2; struct icl_pdu *ip; u_int pdu_len, val; MPASS(m == NULL); /* Must already be assembling a PDU. */ MPASS(icp != NULL); MPASS(icp->icp_flags & ICPF_RX_HDR); /* Data is optional. */ MPASS((icp->icp_flags & ICPF_RX_STATUS) == 0); pdu_len = be16toh(cpl->len); /* includes everything. */ val = be32toh(cpl->ddpvld); #if 0 CTR5(KTR_CXGBE, "%s: tid %u, cpl->len %u, ddpvld 0x%08x, icp_flags 0x%08x", __func__, tid, pdu_len, val, icp->icp_flags); #endif icp->icp_flags |= ICPF_RX_STATUS; ip = &icp->ip; if (val & F_DDP_PADDING_ERR) icp->icp_flags |= ICPF_PAD_ERR; if (val & F_DDP_HDRCRC_ERR) icp->icp_flags |= ICPF_HCRC_ERR; if (val & F_DDP_DATACRC_ERR) icp->icp_flags |= ICPF_DCRC_ERR; if (val & F_DDP_PDU && ip->ip_data_mbuf == NULL) { MPASS((icp->icp_flags & ICPF_RX_FLBUF) == 0); MPASS(ip->ip_data_len > 0); icp->icp_flags |= ICPF_RX_DDP; counter_u64_add(ci->ddp_pdus, 1); counter_u64_add(ci->ddp_bytes, ip->ip_data_len); } INP_WLOCK(inp); if (__predict_false(inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT))) { CTR4(KTR_CXGBE, "%s: tid %u, rx (%d bytes), inp_flags 0x%x", __func__, tid, pdu_len, inp->inp_flags); INP_WUNLOCK(inp); icl_cxgbei_conn_pdu_free(NULL, ip); #ifdef INVARIANTS toep->ulpcb2 = NULL; #endif return (0); } tp = intotcpcb(inp); MPASS(icp->icp_seq == tp->rcv_nxt); MPASS(tp->rcv_wnd >= pdu_len); tp->rcv_nxt += pdu_len; tp->rcv_wnd -= pdu_len; tp->t_rcvtime = ticks; /* update rx credits */ toep->rx_credits += pdu_len; t4_rcvd(&toep->td->tod, tp); /* XXX: sc->tom_softc.tod */ so = inp->inp_socket; sb = &so->so_rcv; SOCKBUF_LOCK(sb); icc = toep->ulpcb; if (__predict_false(icc == NULL || sb->sb_state & SBS_CANTRCVMORE)) { CTR5(KTR_CXGBE, "%s: tid %u, excess rx (%d bytes), icc %p, sb_state 0x%x", __func__, tid, pdu_len, icc, sb->sb_state); SOCKBUF_UNLOCK(sb); INP_WUNLOCK(inp); INP_INFO_RLOCK(&V_tcbinfo); INP_WLOCK(inp); tp = tcp_drop(tp, ECONNRESET); if (tp) INP_WUNLOCK(inp); INP_INFO_RUNLOCK(&V_tcbinfo); icl_cxgbei_conn_pdu_free(NULL, ip); #ifdef INVARIANTS toep->ulpcb2 = NULL; #endif return (0); } MPASS(icc->icc_signature == CXGBEI_CONN_SIGNATURE); ic = &icc->ic; icl_cxgbei_new_pdu_set_conn(ip, ic); MPASS(m == NULL); /* was unused, we'll use it now. */ m = sbcut_locked(sb, sbused(sb)); /* XXXNP: toep->sb_cc accounting? */ if (__predict_false(m != NULL)) { int len = m_length(m, NULL); /* * PDUs were received before the tid transitioned to ULP mode. * Convert them to icl_cxgbei_pdus and send them to ICL before * the PDU in icp/ip. */ CTR3(KTR_CXGBE, "%s: tid %u, %u bytes in so_rcv", __func__, tid, len); /* XXXNP: needs to be rewritten. */ if (len == sizeof(struct iscsi_bhs) || len == 4 + sizeof(struct iscsi_bhs)) { struct icl_cxgbei_pdu *icp0; struct icl_pdu *ip0; ip0 = icl_cxgbei_new_pdu(M_NOWAIT); icl_cxgbei_new_pdu_set_conn(ip0, ic); if (ip0 == NULL) CXGBE_UNIMPLEMENTED("PDU allocation failure"); icp0 = ip_to_icp(ip0); icp0->icp_seq = 0; /* XXX */ icp0->icp_flags = ICPF_RX_HDR | ICPF_RX_STATUS; m_copydata(m, 0, sizeof(struct iscsi_bhs), (void *)ip0->ip_bhs); STAILQ_INSERT_TAIL(&icc->rcvd_pdus, ip0, ip_next); } m_freem(m); } STAILQ_INSERT_TAIL(&icc->rcvd_pdus, ip, ip_next); if ((icc->rx_flags & RXF_ACTIVE) == 0) { struct cxgbei_worker_thread_softc *cwt = &cwt_softc[icc->cwt]; mtx_lock(&cwt->cwt_lock); icc->rx_flags |= RXF_ACTIVE; TAILQ_INSERT_TAIL(&cwt->rx_head, icc, rx_link); if (cwt->cwt_state == CWT_SLEEPING) { cwt->cwt_state = CWT_RUNNING; cv_signal(&cwt->cwt_cv); } mtx_unlock(&cwt->cwt_lock); } SOCKBUF_UNLOCK(sb); INP_WUNLOCK(inp); #ifdef INVARIANTS toep->ulpcb2 = NULL; #endif return (0); }
static void write_gcda(char *addr, struct gcov_info* gi) { const char* filename = SKIBOOT_ADDR(addr, gi->filename); int fd; u32 fn; struct gcov_fn_info *fn_info; struct gcov_fn_info **functions; struct gcov_ctr_info *ctr_info; u32 ctr; u32 cv; printf("Writing %s\n", filename); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if (fd < 0) { fprintf(stderr, "Error opening file %s: %d %s\n", filename, errno, strerror(errno)); exit(EXIT_FAILURE); } write_u32(fd, GCOV_DATA_MAGIC); write_u32(fd, be32toh(gi->version)); write_u32(fd, be32toh(gi->stamp)); //printf("nfunctions: %d \n", be32toh(gi->n_functions)); for(fn = 0; fn < be32toh(gi->n_functions); fn++) { functions = (struct gcov_fn_info**) SKIBOOT_ADDR(addr, gi->functions); fn_info = (struct gcov_fn_info*) SKIBOOT_ADDR(addr, functions[fn]); write_u32(fd, GCOV_TAG_FUNCTION); write_u32(fd, GCOV_TAG_FUNCTION_LENGTH); write_u32(fd, be32toh(fn_info->ident)); write_u32(fd, be32toh(fn_info->lineno_checksum)); write_u32(fd, be32toh(fn_info->cfg_checksum)); ctr_info = (struct gcov_ctr_info*) ((char*)fn_info + sizeof(struct gcov_fn_info)); for(ctr = 0; ctr < GCOV_COUNTERS; ctr++) { if (!counter_active(gi, ctr)) continue; write_u32(fd, (GCOV_TAG_FOR_COUNTER(ctr))); write_u32(fd, be32toh(ctr_info->num)*2); /* printf(" ctr %d gcov_ctr_info->num %u\n", * ctr, be32toh(ctr_info->num)); */ for(cv = 0; cv < be32toh(ctr_info->num); cv++) { gcov_type *ctrv = (gcov_type *) SKIBOOT_ADDR(addr, ctr_info->values); //printf("%lx\n", be64toh(ctrv[cv])); write_u64(fd, be64toh(ctrv[cv])); } ctr_info++; } } close(fd); }