int main(int argc, char *argv[]) { const char keyString[] = "455554"; const unsigned char testMessage[] = "Hello world!"; //Note! Digest is the mac, actual length of the MAC is placed in md_len (named rc in this code), do not use strlen // printMac(testMessage,keyString,0); // printMac((unsigned char *)"This is a message...",keyString,0); // printMac((unsigned char *)"Hello world!",keyString,0); if(argc>1) //passing public key as argument to use as key to hmac,tested with public key of server { struct stat sb; int rc = stat(argv[1],&sb); if(rc == -1) return EXIT_FAILURE; fprintf(stderr,"size of %s is: %li bytes\n",argv[1],sb.st_size); // return EXIT_SUCCESS; FILE *fp = fopen(argv[1],"r"); if(!fp) return EXIT_FAILURE; //can also be used to get size// /* long lSize; fseek (fp , 0 , SEEK_END); lSize = ftell (fp); rewind (fp); // fprintf(stderr,"size of %s is: %li bytes\n",argv[1],lSize); */ char * keyBuff = calloc(sb.st_size,sizeof(char)); rc = fread(keyBuff,sizeof(char),sb.st_size,fp); fclose(fp); if(rc!= sb.st_size) fprintf(stderr,"Incorrect number of bytes read\n"); else fprintf(stdout,"Contents of %s:\n%s\n",argv[1],keyBuff); printMac((unsigned char *)"Hello world!",keyBuff,0); printMac((unsigned char *)"Hello world!",keyBuff,0); free(keyBuff); } return EXIT_SUCCESS; }
static void apac_ctrl_get_msg(int sock, void *eloop_ctx, void *sock_ctx) { char buf[2048]; int len; struct sockaddr_un from; socklen_t fromlen; char *pos; char *end; apacHyfi20IF_t *pIF = (apacHyfi20IF_t* )eloop_ctx; fromlen = sizeof(from); len = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *) &from, &fromlen); if (len < 0) { perror("recvfrom (unix)"); return ; } dprintf(MSG_MSGDUMP, "get ctrl msg %d\n", len); buf[len] = '\0'; dprintf(MSG_MSGDUMP, "[%s]", buf); pos = buf; end = buf + len; if (*pos == '<') { pos = strchr(pos, '>'); if (pos) pos ++; else pos = buf; } if (strncmp(pos, "FAIL", 4) == 0) { return; } else if (strncmp(pos, "OK", 2) == 0) { return; } else if (strncmp(pos, "PONG", 4) == 0) { return; } else if (strncmp(pos, "WPS-SUCCESS", strlen("WPS-SUCCESS")) == 0) { dprintf(MSG_INFO, "WPS-SUCCESS\n"); } else if (strncmp(pos, "WPS-REG-SUCCESS", strlen("WPS-REG-SUCCESS")) == 0) { //WPS-REG-SUCCESS c4:17:fe:d1:54:1c 4be0c35a-a873-da42-89e6-2144c128e16f u8 wpsEnrolleeMAC[6]; dprintf(MSG_INFO, "WPS-REG-SUCCESS\n"); if (pIF->wlanDeviceMode != APAC_WLAN_AP) return; pos += strlen("WPS-REG-SUCCESS") + 1; if (convertMacStringToHex(pos, (char*)wpsEnrolleeMAC) < 0 ) { dprintf(MSG_INFO, "Invalid Enrollee MAC address\n"); return; } dprintf(MSG_INFO, "Wifi node added by WPS:"); printMac(MSG_INFO, wpsEnrolleeMAC); /*hostapd will send WPS-REG-SUCCESS to all control interfaces with same UUID. So we will receive this message more than once if multi-AP used. Todo: we should know which AP the STA is really associated with*/ pbcWifiWpsAddNode(pIF->mac_addr, wpsEnrolleeMAC); } else if (strncmp(pos, "CTRL-EVENT-EAP-FAILURE", strlen("CTRL-EVENT-EAP-FAILURE")) == 0) { dprintf(MSG_INFO, "CTRL-EVENT-EAP-FAILURE, WPS session ending\n"); } else { return; } }
int main(int argc, const char * argv[]) { uint8_t **mac_addresses = NULL; char* input; while(1) { int index; size_t len = 0; printf("Enter a Command\n"); getline(&input, &len, stdin); if (strcmp(input, "init\n") == 0) { lx_light_init(); mac_addresses = lx_light_get_macs(); int size = lx_light_get_size(); printf("size is %d\n", size); printMac(mac_addresses, size); printf("Initializing\n"); } else if (strcmp(input, "getMacs\n") == 0) { //mac_addresses = lx_light_get_macs(); int size = lx_light_get_size(); printMac(mac_addresses, size); } else if (strcmp(input, "getName\n") == 0) { uint8_t target[8]; printf("Input Light Bulb Number\n"); scanf("%d", &index); copyMac(mac_addresses, target, index); char *name= lx_light_get_name(target); printf("name = %s\n", name); } else if (strcmp(input, "getPower\n") == 0) { uint8_t target[8]; printf("Input Light Bulb Number\n"); scanf("%d", &index); copyMac(mac_addresses, target, index); if (lx_light_get_on_off(target)) printf("it's on\n"); else printf("it's off\n"); } else if (strcmp(input, "getColor\n") == 0) { uint8_t target[8]; printf("Input Light Bulb Number\n"); scanf("%d", &index); copyMac(mac_addresses, target, index); float *color = lx_light_get_color(target); printf("HSBK = (%f, %f, %f, %f)\n", *(color), *(color +1), *(color + 2), *(color + 3)); } else if (strcmp(input, "setColor\n") == 0) { uint8_t target[8]; printf("Input Light Bulb Number\n"); scanf("%d", &index); copyMac(mac_addresses, target, index); float colors[4]; printf("Input Hue\n"); scanf("%f", &colors[0]); printf("Input Saturation\n"); scanf("%f", &colors[1]); printf("Input Brightness\n"); scanf("%f", &colors[2]); printf("Input Kelvin\n"); scanf("%d", &index); colors[3] = (float) index; for (int i = 0; i < 4; i++) { printf("%f ", colors[i]); } printf("\n"); printf("Input Delay\n"); scanf("%d", &index); lx_light_set_color(target, colors, index); } else if (strcmp(input, "setPower\n") == 0) { uint8_t target[8]; printf("Input Light Bulb Number\n"); scanf("%d", &index); copyMac(mac_addresses, target, index); bool on_off; printf("Input On Or Off\n"); scanf("%d", &index); if (index) { on_off = true; } else { on_off = false; } printf("Input Delay\n"); scanf("%d", &index); lx_light_set_on_off(target, on_off, index); } else if (strcmp(input, "update\n") == 0) { lx_light_get_active(); printf("UPDATING\n"); int size = lx_light_get_size(); mac_addresses = lx_light_get_macs(); printMac(mac_addresses, size); printf("Size is %d\n", size); } else if (strcmp(input, "destroy\n") == 0) { lx_light_destroy(); //return 0; } } }