void main(void) { char x=10; char y=10; CLK->CKDIVR = 0; disableInterrupts(); Init_GPIO(); Init_TIM1(); Init_Clock(); usb_init(); enableInterrupts(); while(usb_ready == 0) { usb_process(); } while(1) { delay(100); if(get_random_byte()>127) { x=-x; y=-y; } data_buffer[0] = 0x00; data_buffer[1] = x; data_buffer[2] = y; data_buffer[3] = 0x00; usb_send_data(&data_buffer[0], 4, 0); } }
int main(void) { struct sigaction sact; int delay; memset(&sact, 0, sizeof(sact)); sact.sa_handler = (void *)(int)sigint_handler; sigaction(SIGINT, &sact, NULL); do { increment_upload(); if (!program_exit) { /* make random delay: 5 min <= delay <= 15 mins */ delay = get_random_byte(); delay = (delay & 0x0f); if (delay < 5) delay += 5; printf("delay between before start %d mins\n", delay); delay *= 60; /* to seconds */ sleep(delay); } } while (!program_exit); printf("exiting...\n"); return 0; }
static ssize_t dice_driver_read(struct file * file, char * buf, size_t count, loff_t *ppos) { //char *dice_driver_str = "Dice, Driver!\n"; char dice_driver_str = get_random_byte(6) + '0'; //printk(KERN_ERR // "%c\n", dice_driver_str); //int len = strlen(dice_driver_str); /* Don't include the null byte. */ /* * We only support reading the whole string at once. */ if (count < 1) return -EINVAL; /* * If file position is non-zero, then assume the string has * been read and indicate there is no more data to be read. */ if (*ppos != 0) return 0; /* * Besides copying the string to the user provided buffer, * this function also checks that the user has permission to * write to the buffer, that it is mapped, etc. */ if (copy_to_user(buf, &dice_driver_str, 1)) return -EINVAL; /* * Tell the user how much data we wrote. */ *ppos = 1; return 1; }
/* Get some random bytes. * * @param dst destination for the bytes * @param dst_n number of bytes to get */ void get_random_bytes(void *dst, int dst_n){ int i; char *p = (char *)dst; for(i = 0; i < dst_n; i++){ *p++ = get_random_byte(); } }
/* dice_read function to call get_random_byte and setting its return value to * an unsigned char. Then sets that char to the buffer. * * @param: struct *file, char *buf, size_t count * @return: ssize_t */ static ssize_t dice_read(struct file * file, char * buf, size_t count) { //calling get_random_byte and setting the value to a char unsigned char c = get_random_byte(5); copy_to_user(buf, &c, 1); //returning 1 return 1; }
void p2p_send_dev_disc_req(void) { UWORD8 *frm_ptr = 0; UWORD16 index = 0; UWORD16 ie_len_offset = 0; frm_ptr = (UWORD8*)mem_alloc(g_shared_pkt_mem_handle, MANAGEMENT_FRAME_LEN); if(frm_ptr == NULL) { return; } TROUT_DBG4("P2P: send a P2P frame..."); add_p2p_mgmt_frame_hdr(frm_ptr, g_p2p_join_req.dev_dscr.grp_bssid); g_p2p_dialog_token = get_random_byte(); /* rand dialog token */ index = add_p2p_pub_act_hdr(frm_ptr, g_p2p_dialog_token, P2P_DEV_DISC_REQ); /* Store the P2P IE length offset */ ie_len_offset = MAC_HDR_LEN + P2P_PUB_ACT_TAG_PARAM_OFF + 1; /*************************************************************************/ /* The following P2P attributes are added as per the P2P v1.1 spec */ /* Table 56—P2P attributes in the Device Discoverability Request frame */ /* - P2P Device ID shall be present */ /* - P2P Group ID shall be present */ /*************************************************************************/ index += add_p2p_device_id_attr(frm_ptr, index, g_p2p_join_req.dev_dscr.dev_addr); index += add_p2p_grp_id_attr(frm_ptr, index, g_p2p_join_req.dev_dscr.grp_bssid, g_p2p_join_req.dev_dscr.grp_ssid); /* Update the P2P IE length */ frm_ptr[ie_len_offset] = index - ie_len_offset - 1; /* Transmit the management frame */ tx_mgmt_frame(frm_ptr, index + FCS_LEN, HIGH_PRI_Q, 0); }
void fill_random(void *buf, size_t length) { while (length--) { *(uint8_t *)buf = get_random_byte(); buf = (uint8_t *)buf + 1; } }
void p2p_send_inv_req(UWORD8 is_persit, UWORD8 go_config, UWORD8 cl_config, UWORD8 *ssid, UWORD8 *go_dev_addr, UWORD8 oper_chan) { UWORD8 *frm_ptr = 0; UWORD16 index = 0; UWORD16 ie_len_offset = 0; TROUT_FUNC_ENTER; frm_ptr = (UWORD8*)mem_alloc(g_shared_pkt_mem_handle, MANAGEMENT_FRAME_LEN); if(frm_ptr == NULL) { TROUT_FUNC_EXIT; return; } TROUT_DBG4("P2P: send a P2P frame..."); add_p2p_mgmt_frame_hdr(frm_ptr, mget_p2p_trgt_dev_id()); g_p2p_dialog_token = get_random_byte(); /* rand dialog token */ index = add_p2p_pub_act_hdr(frm_ptr, g_p2p_dialog_token, P2P_INV_REQ); /* Store the P2P IE length offset */ ie_len_offset = MAC_HDR_LEN + P2P_PUB_ACT_TAG_PARAM_OFF + 1; /*************************************************************************/ /* The following P2P attributes are added as per the P2P v1.1 spec */ /* Table 54—P2P attributes in the GO Negotiation Request frame */ /* - Configuration Timeout shall be present */ /* - Invitation Flags shall be present */ /* - Operating Channel shall be present */ /* - P2P Group BSSID Shall be present if not a persistent */ /* invitation request */ /* - Channel List shall be present */ /* - P2P Group ID Shall be present */ /* - P2P Device Info shall be present */ /*************************************************************************/ index += add_config_timout_attr(frm_ptr, index, go_config, cl_config); index += add_p2p_invit_flag_attr(frm_ptr, index, is_persit); index += add_p2p_oper_chan_attr(frm_ptr, index, oper_chan); if(1 == is_persit) { if(CHECK_BIT(g_persist_list.grp_cap, P2PCAPBIT_GO)) { index += add_grp_bssid_attr(frm_ptr, index, get_p2p_if_address()); } } else { index += add_grp_bssid_attr(frm_ptr, index, mget_bssid()); } index += add_p2p_chan_list_attr(frm_ptr, index); index += add_p2p_grp_id_attr(frm_ptr, index, go_dev_addr, ssid); index += add_p2p_device_info_attr(frm_ptr, index); /* Update the P2P IE length */ frm_ptr[ie_len_offset] = index - ie_len_offset - 1; /* Transmit the management frame */ tx_mgmt_frame(frm_ptr, index + FCS_LEN, HIGH_PRI_Q, 0); TROUT_FUNC_EXIT; }
void p2p_send_go_neg_req(void) { UWORD8 *frm_ptr = 0; UWORD16 index = 0; UWORD16 ie_len_offset = 0; frm_ptr = (UWORD8*)mem_alloc(g_shared_pkt_mem_handle, MANAGEMENT_FRAME_LEN); if(frm_ptr == NULL) { return; } TROUT_DBG4("P2P: send a P2P frame..."); add_p2p_mgmt_frame_hdr(frm_ptr, g_p2p_join_req.dev_dscr.dev_addr); g_p2p_dialog_token = get_random_byte(); /* rand dialog token */ index = add_p2p_pub_act_hdr(frm_ptr, g_p2p_dialog_token, P2P_GO_NEG_REQ); /* Store the P2P IE length offset */ ie_len_offset = MAC_HDR_LEN + P2P_PUB_ACT_TAG_PARAM_OFF + 1; /*************************************************************************/ /* The following P2P attributes are added as per the P2P v1.1 spec */ /* Table 49—P2P attributes in the GO Negotiation Request frame */ /* - P2P Capability shall be present */ /* - Group Owner Intent shall be present */ /* - Configuration Timeout shall be present */ /* - Listen Channel shall be present */ /* - Extended Listen Timing may be present */ /* - Intended P2P Interface Address shall be present */ /* - Channel List shall be present */ /* - P2P Device Info shall be present */ /* - Operating Channel shall be present */ /*************************************************************************/ index += add_p2p_capability_attr(frm_ptr, index, get_p2p_dev_cap(), get_p2p_grp_cap()); index += add_GO_intent_attr(frm_ptr, index); index += add_config_timout_attr(frm_ptr, index, get_config_timeout(), get_config_timeout()); /* Add channel attribute */ index += add_listen_chan_attr(frm_ptr, index); index += add_int_p2p_if_addr_attr(frm_ptr, index); index += add_p2p_chan_list_attr(frm_ptr, index); index += add_p2p_device_info_attr(frm_ptr, index); index += add_p2p_oper_chan_attr(frm_ptr, index, mget_p2p_oper_chan()); /* Update the P2P IE length */ frm_ptr[ie_len_offset] = index - ie_len_offset - 1; /* Add WSC IE. The following Attributes are required as per P2P V1.1 spec*/ /* - Version */ /* - Device Password ID */ index += wps_add_go_neg_frm_wsc_ie(frm_ptr, index, (WPS_PROT_TYPE_T)(get_wps_prot()), get_wps_pass_id()); /* Transmit the management frame */ tx_mgmt_frame(frm_ptr, index + FCS_LEN, HIGH_PRI_Q, 0); }
void p2p_send_prov_disc_req(void) { UWORD8 grp_cap = 0; UWORD8 *frm_ptr = 0; UWORD16 index = 0; UWORD16 ie_len_offset = 0; UWORD16 config_method = 0; TROUT_DBG4("P2P: send a P2P frame..."); frm_ptr = (UWORD8*)mem_alloc(g_shared_pkt_mem_handle, MANAGEMENT_FRAME_LEN); if(frm_ptr == NULL) { return; } add_p2p_mgmt_frame_hdr(frm_ptr, g_p2p_join_req.dev_dscr.dev_addr); g_p2p_dialog_token = get_random_byte(); /* rand dialog token */ index = add_p2p_pub_act_hdr(frm_ptr, g_p2p_dialog_token, P2P_PROV_DISC_REQ); /* Store the P2P IE length offset */ ie_len_offset = MAC_HDR_LEN + P2P_PUB_ACT_TAG_PARAM_OFF + 1; /*************************************************************************/ /* The following P2P attributes are added as per the P2P v1.1 spec */ /* Table 58—P2P attributes in the Provision Discovery Request frame */ /* - P2P Capability shall be present */ /* - P2P device info shall be present */ /* - P2P Group ID shall be present */ /*************************************************************************/ index += add_p2p_capability_attr(frm_ptr, index, get_p2p_dev_cap(), grp_cap); index += add_p2p_device_info_attr(frm_ptr, index); index += add_p2p_grp_id_attr(frm_ptr, index, g_p2p_join_req.dev_dscr.dev_addr, g_p2p_join_req.dev_dscr.grp_ssid); /* Update the P2P IE length */ frm_ptr[ie_len_offset] = index - ie_len_offset - 1; /* Add WSC IE */ switch(get_wps_pass_id_enr()) { case DEV_PASS_ID_USER_SPE: { config_method = WPS_CONFIG_METH_DISPLAY; } break; case DEV_PASS_ID_REG_SPE: { config_method = WPS_CONFIG_METH_KEYPAD; } break; case DEV_PASS_ID_PUSHBUTT: { config_method = WPS_CONFIG_METH_PUSHBUTTON; } break; default: { PRINTD("Invalid password ID for joining\n"); } } /* Add the WSC IE */ index += wps_add_config_method_ie(frm_ptr, index, config_method); /* Transmit the management frame */ tx_mgmt_frame(frm_ptr, index + FCS_LEN, HIGH_PRI_Q, 0); }
static void increment_upload(void) { char tmp_file_name[19] = "/tmp/testXXXXXX"; FILE *command_file = NULL; int file_id, uploaded = 5, delay, record, remainder; record = get_random_byte() % TOTAL_COMMANDS; /* choose record */ file_id = make_tmp_file_name(tmp_file_name); if (file_id == -1) goto increment_upload_quit; command_file = fopen(tmp_file_name, "w"); if (command_file == NULL) { printf("fopen() failed: %s\n", strerror(errno)); unlink(tmp_file_name); goto increment_upload_quit; } fprintf(command_file, "%s", start_command[record]); fclose(command_file); if (send_command_to_server(tmp_file_name) == -1) goto increment_upload_quit; /* make random delay: 40 min <= delay <= 55 mins */ delay = (get_random_byte() & 0x0f) + 40; printf("delay between start and stop packets %d mins\n", delay); delay *= 60; /* to seconds */ remainder = delay; do { remainder = sleep(remainder); if (remainder) printf("program exit in %d mins\n", remainder / 60); } while (remainder); /* make random upload size: 5 Mb <= size <= 15 Mb */ uploaded = get_random_byte() & 0x0f; if (uploaded < 5) uploaded += 5; printf("uploaded %d Mb\n", uploaded); uploaded *= (1024 * 1024); /* to bytes */ memset(&tmp_file_name[12], 'X', sizeof(char) * 6); file_id = make_tmp_file_name(tmp_file_name); if (file_id == -1) goto increment_upload_quit; command_file = fopen(tmp_file_name, "w"); if (command_file == NULL) { printf("fopen() failed: %s\n", strerror(errno)); unlink(tmp_file_name); goto increment_upload_quit; } fprintf(command_file, "%s%d%s", stop_command1[record], uploaded, stop_command2[record]); fclose(command_file); if (send_command_to_server(tmp_file_name) == -1) goto increment_upload_quit; log_data(uploaded / (1024 * 1024), delay / 60, record); return; increment_upload_quit: log_message("error, stage not completed"); }