static void answer_magic(int serialfd, const char *kernel_image, unsigned int kernel_address, const char *cmdline, unsigned int cmdline_address, const char *initrd_image, unsigned int initrd_address) { int kernelfd, initrdfd; struct sfl_frame frame; printf("[FLTERM] Received firmware download request from the device.\n"); kernelfd = open(kernel_image, O_RDONLY); if(kernelfd == -1) { perror("[FLTERM] Unable to open kernel image (request ignored)."); return; } initrdfd = -1; if(initrd_image != NULL) { initrdfd = open(initrd_image, O_RDONLY); if(initrdfd == -1) { perror("[FLTERM] Unable to open initrd image (request ignored)."); close(kernelfd); return; } } write_exact(serialfd, sfl_magic_ack, SFL_MAGIC_LEN); upload_fd(serialfd, "kernel", kernelfd, kernel_address); if(cmdline != NULL) { int len; printf("[FLTERM] Setting kernel command line: '%s'.\n", cmdline); len = strlen(cmdline)+1; if(len > (254-4)) { fprintf(stderr, "[FLTERM] Kernel command line too long, load aborted.\n"); close(initrdfd); close(kernelfd); return; } frame.length = len+4; frame.cmd = SFL_CMD_LOAD; frame.payload[0] = (cmdline_address & 0xff000000) >> 24; frame.payload[1] = (cmdline_address & 0x00ff0000) >> 16; frame.payload[2] = (cmdline_address & 0x0000ff00) >> 8; frame.payload[3] = (cmdline_address & 0x000000ff); strcpy((char *)&frame.payload[4], cmdline); send_frame(serialfd, &frame); frame.length = 4; frame.cmd = SFL_CMD_CMDLINE; frame.payload[0] = (cmdline_address & 0xff000000) >> 24; frame.payload[1] = (cmdline_address & 0x00ff0000) >> 16; frame.payload[2] = (cmdline_address & 0x0000ff00) >> 8; frame.payload[3] = (cmdline_address & 0x000000ff); send_frame(serialfd, &frame); }
/** * \brief Sends the frame at the next backoff boundary */ static void send_frame_at_next_backoff_boundary(void) { uint8_t ack_is_requested; uint32_t now_time_us; /* * Locate the next backoff boundary for the frame transmissiom; * this backoff boundary is the starttime for the frame fransmission. * Use a blocking approach, since next backoff boundary should be close. */ do { pal_get_current_time(&now_time_us); } while (pal_add_time_us(now_time_us, PRE_TX_DURATION_US) < cca_starttime_us); /* re-programm the interrupt handler */ pal_trx_irq_init((FUNC_PTR)ack_reception_handler_cb); pal_trx_irq_en(); /* debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_TX_START(); /* Check if an acknowledgement is requested for this frame. */ ack_is_requested = *(tal_frame_to_tx + 1) & FCF_ACK_REQUEST; if (ack_is_requested > 0) { tal_csma_state = FRAME_SENDING_WITH_ACK; } else { tal_csma_state = FRAME_SENDING_NO_ACK; } /* download and send frame, no CSMA and no frame_retry */ send_frame(NO_CSMA_NO_IFS, false); }
void eventbus_register(String address,void (*func)(String *)){ handler_t handler; handler.address=address; handler.function=func; if(find(address)==false){ jsonMessage_t js; js.address=address; js.type="register"; js.replyAddress=NULL; JSON_Value *body = json_parse_string(NULL); JSON_Value *headers = json_parse_string(NULL); js.body=body; js.headers=headers; String message=NULL; getMessage(js,&message); send_frame(&message); free(message); } insertFirst(node_index,handler); node_index++; }
int main(void) { uint8_t i; PORTB = 0; DDRB = (1<<PB1); TCCR1B = (1<<CS10); // test mode enable PORTB = (1<<PB1); _delay_ms(75); PORTB = 0; UCSRB = (1<<RXCIE) | (1<<RXEN) | (1<<TXEN); UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0); UBRRH = 0; UBRRL = 12; sei(); while(1) { for(i=1;i<=8;i++) { put_frame(i); put_frame(vals[i-1]); send_frame(); while(TIMSK) {} // wait while send busy } } return 0; }
static portTASK_FUNCTION(TimeTask,pvParameters) { unsigned char frame[MAX_FRAME_SIZE]; int num_datos; int tiempoSim; uint32_t hora; while(1) { vTaskDelay(configTICK_RATE_HZ); //cada segundo tiempoSim=getTiempoSim(); //Obtenemos la equivalencia de 1 segundo Real son tiempoSim minutos en el simulado hora = getHora(); //Obtenemos la hora hora+=tiempoSim; //aumentamos hora tiempoSim (Minutos) if(hora>1440){ //si llegamos a las 24:00 (1440 minutos) ponemos las 00:00 hora=0; } //Modificamos y enviamos la hora setHora(hora); num_datos=create_frame(frame, COMANDO_TIME, &hora, sizeof(hora), MAX_FRAME_SIZE); if (num_datos>=0){ send_frame(frame, num_datos); }else{ logError(num_datos); } } }
/** * Envoi d'une trame a tous les joueurs encore connectes (broadcast) * S'il y'a un probleme d'envoi, le joueur concerne est deconnecte et desinscrit * * @param the_players Liste des joueurs * @param frame Trame a envoyer */ void send_broadcast(Players the_players, Frame frame) { size_t i = 0; Player current_player; /*debug*/ print_frame(frame); for(i=0; i < the_players->size; i++) { current_player = the_players->player[i]; /* Envoi de la trame a tous les joueurs inscrits * Desinscription et deconnexion du joueur en cas de deconnexion brutale */ if(current_player->is_registered) { if(send_frame(current_player->sock, frame) == ERROR) { /*debug*/ printf("Suppression d'un joueurs"); remove_player_by_sock(current_player->sock, the_players, 1); } } } free_frame(frame); }
void mySendFrame(unsigned char* databuff, int size) {//add crc and cooperate with physical layer. databuff should be ready to send. size shoule be without crc if (databuff[0] != FRAME_NAK) { //piggyback ack short i = (receiverLeft - 1) % windowSize;//log the last ack arrived if (i < 0) i += windowSize; for (short j = 0; j < bufferSize; j++) { if (receiver[(receiverLeft + j) % bufferSize].frameArrived) i = (receiverLeft + j) % windowSize; else break; } databuff[0] == FRAME_DATA ? databuff[2] = i : databuff[1] = i; } //append crc *(unsigned int*)(databuff + size) = crc32(databuff, size); size += 4;//add length if (databuff[0] == FRAME_DATA) //add timer start_timer(databuff[1], retimer); //piggyback ack timer if (databuff[0] != FRAME_NAK) { stop_ack_timer(); start_ack_timer(acktimer); } send_frame(databuff, size); }
/* Handle incoming READY_QUERY frames. */ static void handle_ready_query(Conn_t *conn, struct ready_frame *f) { f->opcode = htons(READY_IND); send_frame(conn, f, sizeof(struct ready_frame)); return; }
void send_auth(struct params* p, char *mac) { char buf[4096]; struct ieee80211_frame *wh; unsigned short *ptr; int len; wh = (struct ieee80211_frame*) buf; memset(buf, 0, sizeof(buf)); fill_basic(wh, p); memcpy(wh->i_addr1, mac, 6); memcpy(wh->i_addr3, p->mac, 6); wh->i_fc[0] |= IEEE80211_FC0_TYPE_MGT; wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_AUTH; ptr = (unsigned short*) (wh+1); *ptr++ = htole16(0); *ptr++ = htole16(2); *ptr++ = htole16(0); len = ((char*)ptr) - ((char*) wh); printf("sending auth\n"); send_frame(p, wh, len); }
uint64 pcnet_send(struct eth_dev *e, uint8 *d, uint64 len, uint8 dst[6]) { struct pcnet_private *p = (struct pcnet_private *)e->phys; int i; /* printf("pcnet_send: len=%x dst=", len); print_mac(dst); printf("\n"); */ for(i = 0 ; i < DRE_COUNT ; i++) { if(!p->tx[i].TBADR) { p->tx[i].ones = 0xf; p->tx[i].TBADR = (uint32)(uint64)kmalloc_align(1544, "pcnet_tx_32", NULL); } if(!p->tx[i].OWN) { send_frame(&p->tx[i], e->addr, dst, d, len); p->tx[i].ADD_NO_FCS = 1; p->tx[i].ENP = 1; p->tx[i].STP = 1; p->tx[i].OWN = 1; } } return 0; }
/* Send a LE_ARP_RESPONSE for a LAN destination (MAC address) when * the LAN destination is present in kernel bridging table and we * are acting as a proxy lane client */ static void send_proxy_arp_rsp(unsigned char *target_mac, uint32_t tran_id, uint16_t lec_id, unsigned char *src_atm_addr) { struct ctrl_frame *frame; int frame_size; frame_size = sizeof(struct ctrl_frame) + lec_params.sizeoftlvs; frame = malloc(frame_size); if (frame == NULL) return; memset(frame, 0, frame_size); prefill_frame(frame, LE_ARP_RSP); frame->header.tran_id = tran_id; frame->header.lec_id = lec_id; frame->header.flags = htons(REMOTE_ADDRESS); memcpy(frame->target_atm_addr, lec_params.c1n_my_atm_addr, ATM_ESA_LEN); frame->target_lan_dst.tag = htons(LAN_DST_MAC_ADDR); memcpy(frame->target_lan_dst.mac, target_mac, ETH_ALEN); memcpy(frame->src_atm_addr, src_atm_addr, ATM_ESA_LEN); frame->num_tlvs = lec_params.num_tlvs; if (lec_params.num_tlvs > 0) memcpy(frame + 1, lec_params.tlvs, lec_params.sizeoftlvs); if (send_frame(lec_params.ctrl_direct, frame, frame_size) < 0) diag(COMPONENT, DIAG_ERROR, "send_proxy_arp_rsp: send_frame() failed"); free(frame); return; }
void send_auth(struct params *p) { char buf[2048]; struct ieee80211_frame *wh; char *data; int len; memset(buf, 0, sizeof(buf)); wh = (struct ieee80211_frame*) buf; fill_basic(wh, p); wh->i_fc[0] |= IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_AUTH; data = (char*) (wh + 1); /* algo */ *data++ = 0; *data++ = 0; /* transaction no. */ *data++ = 1; *data++ = 0; /* status code */ *data++ = 0; *data++ = 0; len = data - (char*)wh; send_frame(p, buf, len); }
void send_assoc(struct params *p, char *mac) { char buf[4096]; struct ieee80211_frame *wh; char *ptr; int len; wh = (struct ieee80211_frame*) buf; memset(buf, 0, sizeof(buf)); fill_basic(wh, p); memcpy(wh->i_addr1, mac, 6); memcpy(wh->i_addr3, p->mac, 6); wh->i_fc[0] |= IEEE80211_FC0_TYPE_MGT; wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_ASSOC_RESP; ptr = (char*) (wh+1); *ptr |= IEEE80211_CAPINFO_ESS; ptr += 2; /* cap */ ptr += 2; /* status */ ptr += 2; /* aid */ /* rates */ *ptr++ = 1; *ptr++ = 4; *ptr++ = 2 | 0x80; *ptr++ = 4 | 0x80; *ptr++ = 11; *ptr++ = 22; len = ptr - ((char*) wh); printf("sending assoc response\n"); send_frame(p, wh, len); }
int main(int argc, char *argv[]) { #ifdef IMX int retuid; retuid = setuid(0); // root me! if (retuid == -1) { exit(-10); } #endif // Open the pipe, write the data, close the pipe. pipe_fd = open("/run/pipelights.3.fifo", O_WRONLY); if (pipe_fd == -1) { printf("Failed to open pipe!\n"); exit(-120); } since_start(); // initialize the count of when we started execution // Ok, we're ready to start, so call the setup setup(); synchronize(1); // And setup the sync function while (1) { loop(since_start()); synchronize(20000000); // 50 fps or 20 msec/frame send_frame(pipe_fd, 0L); // Try to transmit the frame } close(pipe_fd); // And close the fifo return 0; }
void relay_data(struct params *p, struct ieee80211_frame *wh, int len) { char seq[2]; char fc[2]; unsigned short *ps; /* copy crap */ memcpy(fc, wh->i_fc, 2); memcpy(seq, wh->i_seq, 2); /* relay frame */ wh->i_fc[1] &= ~(IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_RETRY); wh->i_fc[1] |= IEEE80211_FC1_DIR_FROMDS; memcpy(wh->i_addr1, wh->i_addr3, sizeof(wh->i_addr1)); memcpy(wh->i_addr3, wh->i_addr2, sizeof(wh->i_addr3)); memcpy(wh->i_addr2, p->mac, sizeof(wh->i_addr2)); ps = (unsigned short*)wh->i_seq; *ps = seqfn(p->seq, 0); send_frame(p, wh, len); enque(p, wh, len); /* restore */ memcpy(wh->i_fc, fc, sizeof(fc)); memcpy(wh->i_addr2, wh->i_addr3, sizeof(wh->i_addr2)); memcpy(wh->i_addr3, wh->i_addr1, sizeof(wh->i_addr2)); memcpy(wh->i_addr1, p->mac, sizeof(wh->i_addr1)); memcpy(wh->i_seq, seq, sizeof(seq)); }
void send_beacon(struct params *p) { char buf[4096]; struct ieee80211_frame *wh; int len; char *ptr; wh = (struct ieee80211_frame*) buf; memset(buf, 0, sizeof(buf)); fill_basic(wh, p); memset(wh->i_addr1, 0xff, 6); memcpy(wh->i_addr3, p->mac, 6); wh->i_fc[0] |= IEEE80211_FC0_TYPE_MGT; wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_BEACON; len = fill_beacon(p, wh); /* TIM */ ptr = (char*)wh + len; *ptr++ = 5; *ptr++ = 4; len += 2+4; #if 0 printf("sending beacon\n"); #endif send_frame(p, wh, len); if (gettimeofday(&p->blast, NULL) == -1) err(1, "gettimeofday()"); }
static int can_echo_gen(void) { struct can_frame tx_frames[CAN_MSG_COUNT]; struct can_frame rx_frame; unsigned char counter = 0; int send_pos = 0, recv_pos = 0, unprocessed = 0, loops = 0; int i; while (running) { if (unprocessed < CAN_MSG_COUNT) { /* still send messages */ tx_frames[send_pos].can_dlc = CAN_MSG_LEN; tx_frames[send_pos].can_id = CAN_MSG_ID; for (i = 0; i < CAN_MSG_LEN; i++) tx_frames[send_pos].data[i] = counter + i; if (send_frame(&tx_frames[send_pos])) return -1; /* increment to be equal to expected */ tx_frames[send_pos].can_id++; for (i = 0; i < CAN_MSG_LEN; i++) tx_frames[send_pos].data[i]++; send_pos++; if (send_pos == CAN_MSG_COUNT) send_pos = 0; unprocessed++; if (verbose == 1) echo_progress(counter); counter++; if ((counter % 33) == 0) millisleep(3); else millisleep(1); } else { if (recv_frame(&rx_frame)) return -1; if (verbose > 1) print_frame(&rx_frame); /* compare with expected */ compare_frame(&tx_frames[recv_pos], &rx_frame); loops++; if (test_loops && loops >= test_loops) break; recv_pos++; if (recv_pos == CAN_MSG_COUNT) recv_pos = 0; unprocessed--; } } printf("\nTest messages sent and received: %d\n", loops); return 0; }
void send_probe_request(struct params *p) { char buf[2048]; struct ieee80211_frame *wh; char *data; int len; memset(buf, 0, sizeof(buf)); wh = (struct ieee80211_frame*) buf; fill_basic(wh, p); wh->i_fc[0] |= IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ; memset(wh->i_addr1, 0xFF, 6); memset(wh->i_addr3, 0xFF, 6); data = (char*) (wh + 1); *data++ = 0; /* SSID */ *data++ = strlen(p->ssid); strcpy(data, p->ssid); data += strlen(p->ssid); *data++ = 1; /* rates */ *data++ = 4; *data++ = 2 | 0x80; *data++ = 4 | 0x80; *data++ = 11; *data++ = 22; len = data - (char*)wh; send_frame(p, buf, len); }
static void send_fragment(struct wstate *ws, struct frag_state* fs, struct prga_info *pi) { unsigned char buf[4096]; struct ieee80211_frame* wh; unsigned char* body; int fragsize; uLong crc; unsigned int *pcrc; int i; unsigned short* seq; unsigned short sn, fn; wh = (struct ieee80211_frame*) buf; memcpy(wh, &fs->fs_wh, sizeof(*wh)); body = (unsigned char*) wh + sizeof(*wh); memcpy(body, &pi->pi_iv, 3); body += 3; *body++ = 0; // key index fragsize = fs->fs_data + fs->fs_len - fs->fs_ptr; assert(fragsize > 0); if ( (fragsize + 4) > pi->pi_len) { fragsize = pi->pi_len - 4; wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG; } // last fragment else { wh->i_fc[1] &= ~IEEE80211_FC1_MORE_FRAG; } memcpy(body, fs->fs_ptr, fragsize); crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, body, fragsize); pcrc = (unsigned int*) (body+fragsize); *pcrc = htole32(crc); for (i = 0; i < (fragsize + 4); i++) body[i] ^= pi->pi_prga[i]; seq = (unsigned short*) &wh->i_seq; sn = (le16toh(*seq) & IEEE80211_SEQ_SEQ_MASK) >> IEEE80211_SEQ_SEQ_SHIFT; fn = le16toh(*seq) & IEEE80211_SEQ_FRAG_MASK; // printf ("Sent frag (data=%d) (seq=%d fn=%d)\n", fragsize, sn, fn); send_frame(ws, buf, sizeof(*wh) + 4 + fragsize+4); seq = (unsigned short*) &fs->fs_wh.i_seq; *seq = fnseq(++fn, sn); fs->fs_ptr += fragsize; if (fs->fs_ptr - fs->fs_data == fs->fs_len) { // printf("Finished sending frags...\n"); fs->fs_waiting_relay = 1; } }
int send_tunnel_request_packet(char *remote_host, int remote_port, int friend_number) { int packet_length = 0; protocol_frame frame_i, *frame; char *data = NULL; log_printf(L_INFO, "Sending packet to friend #%d to forward %s:%d\n", friend_number, remote_host, remote_port); packet_length = PROTOCOL_BUFFER_OFFSET + strlen(remote_host); frame = &frame_i; data = calloc(1, packet_length); if(!data) { log_printf(L_ERROR, "Could not allocate memory for tunnel request packet\n"); exit(1); } strcpy(data+PROTOCOL_BUFFER_OFFSET, remote_host); frame->friendnumber = friend_number; frame->packet_type = PACKET_TYPE_REQUESTTUNNEL; frame->connid = remote_port; frame->data_length = strlen(remote_host); send_frame(frame, data); free(data); return 0; }
/*------------------------------------------------------------------*/ static u8_t raven_gui_loop(process_event_t ev, process_data_t data) { if(ev == tcpip_icmp6_event) { switch(*((uint8_t *)data)){ case ICMP6_ECHO_REQUEST: /* We have received a ping request over the air. Send frame back to 3290 */ send_frame(PING_REQUEST, 0, 0); break; case ICMP6_ECHO_REPLY: /* We have received a ping reply over the air. Send frame back to 3290 */ send_frame(PING_REPLY, 1, &seqno); break; } } else { switch(ev){ case SERIAL_CMD: /* Check for command from serial port, execute it. */ if (cmd.done){ /* Execute the waiting command */ switch (cmd.cmd){ case CMD_PING: /* Send ping request over the air */ seqno = cmd.frame[0]; raven_ping6(); break; case CMD_TEMP: /* Set temperature string in web server */ sprintf(udp_data, "T%s\r\n", (char *)cmd.frame); uip_udp_packet_send(udp_conn, udp_data, data_len); break; default: break; } /* Reset command done flag. */ cmd.done = false; } break; default: break; } } return 0; }
void send_frame_to_all(nw_cmd_t cmd) { std::vector<int>::iterator it; for(it = clients.begin(); it<clients.end(); ++it) { if(!send_frame(*it, no_addr, cmd, vars)) { clients.erase(it); } } }
/* Send an 8-bit byte from LSB to MSB */ void send_byte(uint8_t data) { printf("sending byte 0x%02x\n", data); uint8_t i; for (i = 0; i < 4; i++) { send_frame(data); data >>= 2; } }
void WebSocket::close(Client* client) { if(client->established) { send_frame(client, 0x8, nullptr, 0); } delete client->sck; client->sck = nullptr; m_closed_clients.push_back(client); }
void send_colors(int fd) { send_frame(fd, "ColorTest,SetDutyCycles,%d,%d,%d,%d", lamp->red, lamp->green, lamp->blue, lamp->white); }
void m2comm_device::send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize) { m_buffer0[0] = frameType; for (int i = 0x0000 ; i < frameSize ; i++) { m_buffer0[1 + i] = m_shared[frameStart + i]; } send_frame(dataSize); }
static int can_echo_dut(void) { unsigned int frame_count = 0; struct timeval tvn, tv_stop; struct can_frame frame; int i; while (running) { if (recv_frame(&frame)) return -1; frame_count++; if (verbose == 1) { echo_progress(frame.data[0]); } else if (verbose > 1) { printf("%04x: ", frame.can_id); if (frame.can_id & CAN_RTR_FLAG) { printf("remote request"); } else { printf("[%d]", frame.can_dlc); for (i = 0; i < frame.can_dlc; i++) printf(" %02x", frame.data[i]); } printf("\n"); } frame.can_id++; for (i = 0; i < frame.can_dlc; i++) frame.data[i]++; if (send_frame(&frame)) return -1; /* * to force a interlacing of the frames send by DUT and PC * test tool a waiting time is injected */ if (frame_count == CAN_MSG_WAIT) { frame_count = 0; if (gettimeofday(&tv_stop, NULL)) { perror("gettimeofday failed\n"); return -1; } else { tv_stop.tv_usec += 3000; if (tv_stop.tv_usec > 999999) { tv_stop.tv_sec++; tv_stop.tv_usec = tv_stop.tv_usec % 1000000; } gettimeofday(&tvn, NULL); while ((tv_stop.tv_sec > tvn.tv_sec) || ((tv_stop.tv_sec = tvn.tv_sec) && (tv_stop.tv_usec >= tvn.tv_usec))) gettimeofday(&tvn, NULL); } } } return 0; }
void s32comm_device::send_data(uint8_t frameType, int frameStart, int frameSize, int dataSize) { m_buffer0[0] = frameType; for (int i = 0x00 ; i < frameSize ; i++) { m_buffer0[1 + i] = m_shared[frameStart + i]; } // forward message to next node send_frame(dataSize); }
/* Handle incoming LE_FLUSH_REQUEST frames. */ static void handle_flush_req(struct ctrl_frame *f) { if (memcmp(lec_params.c1n_my_atm_addr, f->target_atm_addr, ATM_ESA_LEN) != 0) return; f->header.opcode = htons(LE_FLUSH_RSP); if (send_frame(lec_params.ctrl_direct, f, sizeof(struct ctrl_frame)) < 0) diag(COMPONENT, DIAG_DEBUG, "could not send LE_FLUSH_RESPONSE\n"); return; }
/* 7.1.25 Send a LE_TOPOLOGY_REQUEST */ static void send_topology_req(int flag) { struct ctrl_frame frame; prefill_frame(&frame, LE_TOPO_REQ); if (flag) frame.header.flags = htons(TOPO_CHANGE); send_frame(lec_params.ctrl_direct, &frame, sizeof(struct ctrl_frame)); return; }