static int getMACaddr() { // unsigned char mac[8] = {0}; char buf[64] = {0}; unsigned char temp[8] = {0}; int i = 0, j = 0, k = 0; FILE *fp = popen("ifconfig eth0| awk '/HWaddr/{printf(\"%s\", $5)}'", "r"); fread(buf, 31, 1, fp); pclose(fp); PRINTF("mac:%s\n", buf); for(i = 0; i < 8; i++) { if(buf[j] == '\0') { break; } temp[0] = buf[j]; temp[1] = buf[j + 1]; temp[3] = '\0'; PRINTF("temp=%s \n", temp); g_network_info.szMacAddr[i] = atohex(temp); PRINTF("%2x \n", g_network_info.szMacAddr[i]); j += 3; } return 0; }
void Serial_Ctrl::on_pushButton_serial_send_clicked() { CHD_RET_E ret; if(ui->radioButton_send_hex->isChecked() == true){ unsigned char * buffer = new unsigned char[ui->plainTextEdit_send->toPlainText().length()]; QStringList list; list.append(ui->plainTextEdit_send->toPlainText().split(" ")); for(int i = 0 ;i < list.length(); i++){ buffer[i] = atohex(list.at(i).toLocal8Bit().data()); // qDebug("v = %u", buffer[i]); } ret = CHD_WMP_Serial_SendData(handler, (const char *)buffer, list.length()); if(ret == CHD_RET_SUCCESS){ send_total += list.length(); } delete buffer; } else{ ret = CHD_WMP_Serial_SendData(handler, ui->plainTextEdit_send->toPlainText().toLocal8Bit().data(), ui->plainTextEdit_send->toPlainText().length()); if(ret == CHD_RET_SUCCESS){ // qDebug("Send %d", ui->plainTextEdit_send->toPlainText().length()); send_total += ui->plainTextEdit_send->toPlainText().length(); ui->label_sendtotal->setText(QString::number(send_total)); } else{ qDebug("serial send error ret = %#x", ret); } } }
BYTE CMapFile::GetObjectAddress( const char * cObjName, DWORD * addr ){ CStdString sAux; CStdString sFindObj; int i; char cBuffer[512]; int j; DWORD dwRet; if ( fIn.bad() == true ){ return FALSE; } sFindObj.Format( " %s ", cObjName ); while( fIn.eof() == false ){ fIn.getline( cBuffer, sizeof( cBuffer ) ); sAux = cBuffer; if ( sAux.find( sFindObj.c_str() ) != std::string::npos ){ break; } } if ( fIn.eof() ){ return FALSE; } i = sAux.find_first_of( "0x" ); if ( i == std::string::npos ){ return -1; } i+= 2; j = sAux.find_first_of( " ", i ); sFindObj = sAux.substr( i, j-i ); dwRet = atohex( sFindObj.c_str() ); *addr = dwRet; return TRUE; }
int CXGseScd::FindAppid(const std::string &ied_name, const std::string &ld_inst, const std::string &gocb, u_int32_t &appid) { TiXmlNode *pSubNetNode = m_pCommNode->FirstChild("SubNetwork"); while (pSubNetNode != NULL) { if (GES_MEMCMP(pSubNetNode->ToElement()->Attribute("type"), GSE_GOOSE_TAG)) { TiXmlNode *pConnAPNode = pSubNetNode->FirstChild("ConnectedAP"); while (pConnAPNode != NULL) { if (ied_name == pConnAPNode->ToElement()->Attribute("iedName")) { TiXmlNode *pGSENode = pConnAPNode->FirstChild("GSE"); TiXmlElement *pGSEElement = NULL; while (pGSENode != NULL) { pGSEElement = pGSENode->ToElement(); if (ld_inst == pGSEElement->Attribute("ldInst") && gocb == pGSEElement->Attribute("cbName")) { TiXmlNode *pAddrPNode = pGSENode->FirstChild("Address")->FirstChild("P"); while (pAddrPNode != NULL) { if (pAddrPNode->ToElement()->Attribute("type") == std::string("APPID")) { u_char strAppid[4] = {0}; atohex(pAddrPNode->ToElement()->GetText(), strAppid); appid = (strAppid[0] << 8) + strAppid[1] + 1000; break; } pAddrPNode = pAddrPNode->NextSibling(); } return J_OK; } pGSENode = pGSENode->NextSibling(); } } pConnAPNode = pConnAPNode->NextSibling(); } } pSubNetNode = pSubNetNode->NextSibling(); } return J_NOT_FOUND; }
/**************************************************************************** ** ** ** Name: nas_parser_get_trace_level() ** ** ** ** Description: Returns the value of the logging trace level ** ** ** ** Inputs: None ** ** Others: None ** ** ** ** Outputs: Return: Value of the logging trace level ** ** Others: None ** ** ** ***************************************************************************/ int nas_parser_get_trace_level(void) { return atohex( nasParserCommandLine.options[NAS_PARSER_TRACE_LEVEL].pvalue ); }
bool CharProperty::compile(const char *cfile, const char *ufile, const char *ofile) { scoped_fixed_array<char, BUF_SIZE> line; scoped_fixed_array<char *, 512> col; size_t id = 0; std::vector<Range> range; std::map<std::string, CharInfo> category; std::vector<std::string> category_ary; std::ifstream ifs(WPATH(cfile)); std::istringstream iss(CHAR_PROPERTY_DEF_DEFAULT); std::istream *is = &ifs; if (!ifs) { std::cerr << cfile << " is not found. minimum setting is used" << std::endl; is = &iss; } while (is->getline(line.get(), line.size())) { if (std::strlen(line.get()) == 0 || line[0] == '#') { continue; } const size_t size = tokenize2(line.get(), "\t ", col.get(), col.size()); CHECK_DIE(size >= 2) << "format error: " << line.get(); // 0xFFFF..0xFFFF hoge hoge hgoe # if (std::strncmp(col[0], "0x", 2) == 0) { std::string low = col[0]; std::string high; size_t pos = low.find(".."); if (pos != std::string::npos) { high = low.substr(pos + 2, low.size() - pos - 2); low = low.substr(0, pos); } else { high = low; } Range r; r.low = atohex(low.c_str()); r.high = atohex(high.c_str()); CHECK_DIE(r.low >= 0 && r.low < 0xffff && r.high >= 0 && r.high < 0xffff && r.low <= r.high) << "range error: low=" << r.low << " high=" << r.high; for (size_t i = 1; i < size; ++i) { if (col[i][0] == '#') { break; // skip comments } CHECK_DIE(category.find(std::string(col[i])) != category.end()) << "category [" << col[i] << "] is undefined"; r.c.push_back(col[i]); } range.push_back(r); } else { CHECK_DIE(size >= 4) << "format error: " << line.get(); std::string key = col[0]; CHECK_DIE(category.find(key) == category.end()) << "category " << key << " is already defined"; CharInfo c; std::memset(&c, 0, sizeof(c)); c.invoke = std::atoi(col[1]); c.group = std::atoi(col[2]); c.length = std::atoi(col[3]); c.default_type = id++; category.insert(std::pair<std::string, CharInfo>(key, c)); category_ary.push_back(key); } } CHECK_DIE(category.size() < 18) << "too many categories(>= 18)"; CHECK_DIE(category.find("DEFAULT") != category.end()) << "category [DEFAULT] is undefined"; CHECK_DIE(category.find("SPACE") != category.end()) << "category [SPACE] is undefined"; std::istringstream iss2(UNK_DEF_DEFAULT); std::ifstream ifs2(WPATH(ufile)); std::istream *is2 = &ifs2; if (!ifs2) { std::cerr << ufile << " is not found. minimum setting is used." << std::endl; is2 = &iss2; } std::set<std::string> unk; while (is2->getline(line.get(), line.size())) { const size_t n = tokenizeCSV(line.get(), col.get(), 2); CHECK_DIE(n >= 1) << "format error: " << line.get(); const std::string key = col[0]; CHECK_DIE(category.find(key) != category.end()) << "category [" << key << "] is undefined in " << cfile; unk.insert(key); } for (std::map<std::string, CharInfo>::const_iterator it = category.begin(); it != category.end(); ++it) { CHECK_DIE(unk.find(it->first) != unk.end()) << "category [" << it->first << "] is undefined in " << ufile; } std::vector<CharInfo> table(0xffff); { std::vector<std::string> tmp; tmp.push_back("DEFAULT"); const CharInfo c = encode(tmp, &category); std::fill(table.begin(), table.end(), c); } for (std::vector<Range>::const_iterator it = range.begin(); it != range.end(); ++it) { const CharInfo c = encode(it->c, &category); for (int i = it->low; i <= it->high; ++i) { table[i] = c; } } // output binary table { std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); CHECK_DIE(ofs) << "permission denied: " << ofile; unsigned int size = static_cast<unsigned int>(category.size()); ofs.write(reinterpret_cast<const char*>(&size), sizeof(size)); for (std::vector<std::string>::const_iterator it = category_ary.begin(); it != category_ary.end(); ++it) { char buf[32]; std::fill(buf, buf + sizeof(buf), '\0'); std::strncpy(buf, it->c_str(), sizeof(buf) - 1); ofs.write(reinterpret_cast<const char*>(buf), sizeof(buf)); } ofs.write(reinterpret_cast<const char*>(&table[0]), sizeof(CharInfo) * table.size()); ofs.close(); } return true; }
int main(int argc, char *argv[]) { int ret = 0, input = -1; wpa_printf(MSG_DEBUG, "%s", "Hello rild"); while(1){ dumpMenu(); scanf("%d", &input); printf("Input %d\n", input); switch (input) { case 0: { char *pSimResult1 = "8944F433373A7603DE84C000"; char *pSimResult2 = "ERROR,rild is not setup up"; char *pAkaSuccess = "DB083F7D8D419277AE1C1080BB43519D0175C139187861DC01A31A10AC98E8D86AF2D92CA0CAC30B5C50E88A08B5F110E377A2E77D"; char *pAkaFailure = "DC0E8944F438944F438944F438944F43"; u8 i = 0xcd, ia; char *a = "f4", ai[2]; u8 ii[2] = {0x44, 0xfb}, aaii[2]; char *aa = "ffee", iiaa[4]; wpa_printf(MSG_DEBUG, "FIXED TEST\n"); hextoa(&i, ai); wpa_printf(MSG_DEBUG, "%x -> %c%c", i, ai[0], ai[1]); atohex(a, &ia); wpa_printf(MSG_DEBUG, "%s -> %x", a, ia); hextostr(ii, sizeof(ii)/sizeof(ii[0]), iiaa); wpa_printf(MSG_DEBUG, "%x%x -- > %c%c%c%c", ii[0], ii[1], iiaa[0], iiaa[1], iiaa[2], iiaa[3]); strtohex(aa, strlen(aa), aaii); wpa_printf(MSG_DEBUG, "%s --> %x%x", aa, aaii[0], aaii[1]); uint8 *strParm = (uint8 *)pSimResult1, strLen = strlen(pSimResult1); uint8 sres[SIM_SRES_LEN], kc[SIM_KC_LEN]; uint8 res[50]; size_t res_len = 0; uint8 ck[50], ik[50], auts[50]; parseSimResult(strParm, strLen, sres, kc); strParm = (uint8 *)pSimResult2, strLen = strlen(pSimResult2); parseSimResult(strParm, strLen, sres, kc); parseAkaResult(pAkaSuccess, strlen(pAkaSuccess), res, &res_len, ck, ik, auts); parseAkaResult(pAkaFailure, strlen(pAkaFailure), res, &res_len, ck, ik, auts); } break; case 1: { int sock = -1; int i = 0; char *simInput = "EAP_SIM,0,5a01d5224f14222c5554102a10df5896"; int slotId = 0; uint8 sres[SIM_SRES_LEN], kc[SIM_KC_LEN]; uint8 rand[] = {0x5a, 0x01, 0xd5, 0x22, 0x4f, 0x14, 0x22, 0x2c, 0x55, 0x5, 0x4, 0x10, 0x2a, 0x10, 0xdf, 0x58, 0x96}; uint8 randLeon[3][16] = {{0x89, 0xab, 0xcb, 0xee, 0xf9, 0xab, 0xcd, 0xef, 0x89, 0xab, 0xcd, 0xef, 0x89, 0xab, 0xcd, 0xef}, {0x9a, 0xbc, 0xde, 0xf8, 0x9a, 0xbc, 0xde, 0xf8, 0x9a, 0xbc, 0xde, 0xf8, 0x9a, 0xbc, 0xde, 0xf8}, {0xab, 0xcd, 0xef, 0x89, 0xab, 0xcd, 0xef, 0x89, 0xab, 0xcd, 0xef, 0x89, 0xab, 0xcd, 0xef, 0x89}}; for(i = 0; i < 3; i++){ sock = connectToRild(&slotId); eapSimSetParam(sock, 0, randLeon[i]); eapSimQueryResult(sock, sres, kc); disconnectRild(sock); } } break; case 2: { int sock = -1; char *akaInput = "EAP_AKA,0, 8090a966d69c5dd3b5fb0ae975596961,d7ac9c65801a3412af8d47b4ce54ee1e"; int slotId = 0; uint8 rand[] = {0x80, 0x90, 0xa9, 0x66, 0xd6, 0x9c, 0x5d, 0xd3, 0xb5, 0xfb, 0x0a, 0xe9, 0x75, 0x59, 0x69, 0x61}; uint8 autn[] = {0xd7,0xac,0x9c,0x65,0x80,0x1a,0x34,0x12, 0xaf,0x8d,0x47,0xb4,0xce,0x54,0xee,0x1e}; uint8 res[100], ik[100], ck[100], auts[100]; size_t res_len; sock = connectToRild(&slotId); eapAkaSetParam(sock, 0, rand, autn); eapAkaQueryResult(sock, res, &res_len, ik, ck, auts); disconnectRild(sock); } break; default: printf("wrong input %d\n", input); break; } } return 0; }