int run_StartSpeedTest(struct C_HDPLC_EXTCMD_IF *inPlc) { T_HDPLC_EXTCMD_START_SPEEDTEST_REQ *theReq; int ret; char theBuf[64]; char c; int i=0; ret=Initialize(inPlc,D_COM_START_SPEEDTEST,sizeof(T_HDPLC_EXTCMD_START_SPEEDTEST_REQ)); if(ret == D_RETURN_SUCCESS) { theReq = (T_HDPLC_EXTCMD_START_SPEEDTEST_REQ *)GetCmdBody(inPlc); printf("Please enter Mac address (6Byte) -->"); //gets(theBuf); while((c=getc(stdin))!=13) { theBuf[i]=c; printf("%c",c); i++; } theBuf[i]='\0'; printf("\n\r"); String2Hex(theBuf,(char *)theReq->macAddr); return D_RETURN_SUCCESS; }else return D_RETURN_FAILURE; }
/*CINR related difinitions*/ int run_StartChannelEstimate(struct C_HDPLC_EXTCMD_IF *inPlc) { int i; T_HDPLC_EXTCMD_START_CHANNELESTIMATE_REQ *theReq; Initialize(inPlc,D_COM_START_CHANNELESTIMATE,sizeof(T_HDPLC_EXTCMD_START_CHANNELESTIMATE_REQ)); theReq=(T_HDPLC_EXTCMD_START_CHANNELESTIMATE_REQ *)GetCmdBody(inPlc); for(i=0;i<12;i++) { inMac[i]=inStr[i+1]; } inMac[i]='\0'; String2Hex(inMac,(char *)theReq->macAddr); return D_RETURN_SUCCESS; }
std::string AESEncrypt(const std::string& key, const std::string& in) { std::string out; if (key.length() != AES_KEY_LENGTH) { return out; } std::string src = PKCS5Padding(in); AES_KEY aes_key; AES_set_encrypt_key((unsigned char *)key.c_str(), AES_KEY_LENGTH * 8, &aes_key); unsigned char *p = (unsigned char *)src.c_str(); for (int i = 0; i < src.length() / AES_BLOCK_SIZE; ++i) { unsigned char dec[AES_BLOCK_SIZE] = {'\0'}; AES_ecb_encrypt(p + i * AES_BLOCK_SIZE, dec, &aes_key, AES_ENCRYPT); out.append(String2Hex(dec, AES_BLOCK_SIZE)); } return out; }