int main(int argc, char *argv[]) { int fd1; int fd2; int fd3; if(argc != 4) //要求参数必须要有4个 argv[0]装字符串数组的路径,argv[1].argv[2]装被处理的两个字符串,argv[3] { //装处理后合并的数据 printf("param error!\n"); exit(1); } if((fd1 = open(argv[1],O_RDONLY)) == -1) // 要求argv[1]只能进行读操作 { perror("open file error!"); exit(1); } if((fd2 = open(argv[2],O_RDONLY)) == -1)//要求argv[2]只能进行读操作 { perror("open file error!"); exit(1); } if((fd3 = open(argv[3],O_CREAT | O_WRONLY)) == -1)//argv[3]进行写操作 { perror("open file error!"); exit(1); } handle_data(fd1, fd2, fd3);//调用函数处理字符串 return 0; }
int ACE_TMAIN (int, ACE_TCHAR *[]) { u_short port = ACE_DEFAULT_SERVER_PORT + 1; // Create a server end-point. ACE_INET_Addr addr (port); ACE_SSL_SOCK_Acceptor peer_acceptor (addr); ACE_HANDLE s_handle = peer_acceptor.get_handle (); init_poll_array (); poll_array[0].fd = s_handle; ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting oneway server at port %d\n", port)); for (size_t n_handles = 1;;) { // Wait for client I/O events (handle interrupts). while (ACE_OS::poll (poll_array, n_handles) == -1 && errno == EINTR) continue; handle_data (n_handles); handle_connections (peer_acceptor, n_handles); } /* NOTREACHED */ return 0; }
/* handle an incoming packet, acking it if it is a data packet for us * returns the message length > 0 if this was a valid data message from a peer. * if it gets a valid key, returns -1 (details below) * Otherwise returns 0 and does not fill in any of the following results. * * if it is a data or ack, it is saved in the xchat log * if it is a valid data message from a peer or a broadcaster, * fills in verified and broadcast * fills in contact, message (to point to malloc'd buffers, must be freed) * if not broadcast, fills in desc (also malloc'd), sent (if not null) * and duplicate. * if verified and not broadcast, fills in kset. * the data message (if any) is null-terminated * * if kcontact and ksecret1 are not NULL, assumes we are also looking * for key exchange messages sent to us matching either of ksecret1 or * (if not NULL) ksecret2. If such a key is found, returns -1. * there are two ways of calling this: * - if the user specified the peer's secret, first send initial key, * then call handle_packet with our secret in ksecret1 and our * peer's secret in ksecret2. * - otherwise, put our secret in ksecret1, make ksecret2 and kaddr NULL, * and handle_packet is ready to receive a key. * In either case, if a matching key is received, it is saved and a * response is sent (if a response is a duplicate, it does no harm). * kmax_hops specifies the maximum hop count of incoming acceptable keys, * and the hop count used in sending the key. * * if subscription is not null, listens for a reply containing a key * matching the subscription, returning -2 if a match is found. */ int handle_packet (int sock, char * packet, int psize, char ** contact, keyset * kset, char ** message, char ** desc, int * verified, time_t * sent, int * duplicate, int * broadcast, char * kcontact, char * ksecret1, char * ksecret2, int kmax_hops, char * subscription, unsigned char * addr, int nbits) { if (! is_valid_message (packet, psize)) return 0; struct allnet_header * hp = (struct allnet_header *) packet; int hsize = ALLNET_SIZE (hp->transport); if (psize < hsize) return 0; #ifdef DEBUG_PRINT if (hp->hops > 0) /* not my own packet */ print_packet (packet, psize, "xcommon received", 1); #endif /* DEBUG_PRINT */ if (hp->message_type == ALLNET_TYPE_ACK) { handle_ack (sock, packet, psize, hsize); return 0; } if (hp->message_type == ALLNET_TYPE_CLEAR) { /* a broadcast packet */ if ((subscription != NULL) && (addr != NULL)) { int sub = handle_sub (sock, hp, packet + hsize, psize - hsize, subscription, addr, nbits); #ifdef DEBUG_PRINT printf ("handle_sub (%d, %p, %p, %d, %s, %p, %d) ==> %d\n", sock, hp, packet + hsize, psize - hsize, subscription, addr, nbits, sub); #endif /* DEBUG_PRINT */ if (sub > 0) /* received a key in response to our subscription */ return sub; } #ifdef DEBUG_PRINT else printf ("subscription %p, addr %p, did not call handle_sub\n", subscription, addr); #endif /* DEBUG_PRINT */ return handle_clear (hp, packet + hsize, psize - hsize, contact, message, verified, broadcast); } if (hp->message_type == ALLNET_TYPE_DATA) /* an encrypted data packet */ return handle_data (sock, hp, packet + hsize, psize - hsize, contact, kset, message, desc, verified, sent, duplicate, broadcast); if (hp->message_type == ALLNET_TYPE_KEY_XCHG) return handle_key (sock, hp, packet + hsize, psize - hsize, kcontact, ksecret1, ksecret2, kmax_hops); return 0; }
/** * Updates the socket client. This method needs to be called periodically. * @param transport Transport handle */ lwpb_err_t lwpb_transport_socket_client_update(lwpb_transport_t transport) { struct lwpb_transport_socket_client *socket_client = (struct lwpb_transport_socket_client *) transport; int i; int socket; struct timeval timeout; fd_set read_fds; int high; if (socket_client->socket == -1) return; timeout.tv_sec = 1; timeout.tv_usec = 0; // Create set of active sockets high = socket_client->socket; FD_ZERO(&read_fds); FD_SET(socket_client->socket, &read_fds); // Wait for socket to get active i = select(high + 1, &read_fds, NULL, NULL, &timeout); if (i < 0) LWPB_FAIL("select() failed"); if (i == 0) return LWPB_ERR_OK; // Handle data handle_data(socket_client); return LWPB_ERR_OK; }
int main() { init_epoll(); create_socket(); setup_signals(); while (running) { struct epoll_event event; int ret = epoll_wait(epoll_fd, &event, 1, -1); if (ret == 0) continue; if (ret < 0) { if (errno == EINTR) continue; syslog(LOG_ERR, "epoll_wait: %s\n", strerror(errno)); exit(1); } if (event.data.ptr == &listen_event) handle_accept(event.events); else handle_data(event.data.ptr); } cleanup(); }
static EVENT_HANDLER(physical_ready){ //printf("PR called!\n"); int link; FRAME f; size_t length = sizeof(FRAME); CHECK(CNET_read_physical(&link, (char*)&f, &length)); printf("Packet received from %d, via %d\n", f.payload.source, f.payload.dest); //DATA LINK LAYER - check if checksum matches int cs = f.checksum; f.checksum = 0; if(CNET_ccitt((unsigned char*)&f, (int)length) != cs){ printf("Bad Checksum - ignoring frame!\n"); return; } switch(f.payload.kind){ case RT_DATA : update_table(link, f, length); break; case DL_DATA : handle_data(link, f, length); break; case DL_ACK : handle_ack(link, f.payload); break; default : printf("The world is not enough!\n"); break; } //printf("Packet successfully processed!"); }
int main(int argc , char *argv[]) { WSADATA wsa; SOCKET s , new_socket; struct sockaddr_in serveraddr , clientaddr; int addrlen; int n; if (WSAStartup(MAKEWORD(2,2),&wsa) != 0) { printf("Failed. Error Code : %d",WSAGetLastError()); return 1; } printf("Winsock initialised.\n"); //Create a socket if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET) { printf("Could not create socket : %d" , WSAGetLastError()); } printf("Socket created.\n"); //Prepare the sockaddr_in structure serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = INADDR_ANY; serveraddr.sin_port = htons( PORT ); //Bind if( bind(s ,(struct sockaddr *)&serveraddr , sizeof(serveraddr)) == SOCKET_ERROR) { printf("Bind failed with error code : %d" , WSAGetLastError()); exit(EXIT_FAILURE); } printf("Bind done\n"); //Listen to incoming connections listen(s , 3); //Accept and incoming connection printf("Waiting for incoming connections...\n"); addrlen = sizeof(struct sockaddr_in); while( (new_socket = accept(s , (struct sockaddr *)&clientaddr, &addrlen)) != INVALID_SOCKET ) { printf("Connection accepted\n"); do { n = recvfrom(new_socket, buf, BUFSIZE, 0, (struct sockaddr *) &clientaddr, &addrlen); handle_data(buf, n); } while (n > 0); } if (new_socket == INVALID_SOCKET) { printf("accept failed with error code : %d" , WSAGetLastError()); return 1; } closesocket(s); WSACleanup(); return 0; }
static void handle_frame(struct hostap_driver_data *drv, u8 *buf, size_t len) { struct ieee80211_hdr *hdr; u16 fc, type, stype; size_t data_len = len; int ver; union wpa_event_data event; /* PSPOLL is only 16 bytes, but driver does not (at least yet) pass * these to user space */ if (len < 24) { wpa_printf(MSG_MSGDUMP, "handle_frame: too short (%lu)", (unsigned long) len); return; } hdr = (struct ieee80211_hdr *) buf; fc = le_to_host16(hdr->frame_control); type = WLAN_FC_GET_TYPE(fc); stype = WLAN_FC_GET_STYPE(fc); if (type != WLAN_FC_TYPE_MGMT || stype != WLAN_FC_STYPE_BEACON) { wpa_hexdump(MSG_MSGDUMP, "Received management frame", buf, len); } ver = fc & WLAN_FC_PVER; /* protocol version 2 is reserved for indicating ACKed frame (TX * callbacks), and version 1 for indicating failed frame (no ACK, TX * callbacks) */ if (ver == 1 || ver == 2) { handle_tx_callback(drv, buf, data_len, ver == 2 ? 1 : 0); return; } else if (ver != 0) { printf("unknown protocol version %d\n", ver); return; } switch (type) { case WLAN_FC_TYPE_MGMT: os_memset(&event, 0, sizeof(event)); event.rx_mgmt.frame = buf; event.rx_mgmt.frame_len = data_len; wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event); break; case WLAN_FC_TYPE_CTRL: wpa_printf(MSG_DEBUG, "CTRL"); break; case WLAN_FC_TYPE_DATA: wpa_printf(MSG_DEBUG, "DATA"); handle_data(drv, buf, data_len, stype); break; default: wpa_printf(MSG_DEBUG, "unknown frame type %d", type); break; } }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { wpa_printf(MSG_ERROR, "recv: %s", strerror(errno)); return; } handle_data(eloop_ctx, buf, len); }
void handle_usb_request(int sockfd, USBIP_RET_SUBMIT *ret, int bl) { if(ret->ep == 0) { printf("#control requests\n"); handle_usb_control(sockfd, ret); } else { printf("#data requests\n"); handle_data(sockfd, ret, bl); } };
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); return; } handle_data(eloop_ctx, buf, len); }
/*---------------------------------------------------------------------------*/ static void recv_trickle(struct trickle_conn *trickle) { struct rudolph1_conn *c = (struct rudolph1_conn *)trickle; struct rudolph1_datapacket *p = packetbuf_dataptr(); if(p->h.type == TYPE_DATA) { PRINTF("%d.%d: received trickle with chunk %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], p->h.chunk); handle_data(c, p); } }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx; int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); return; } handle_data(hapd, buf, len); }
void handle_dude(int dude, int raw) { char buf[4096]; int rd; while (1) { rd = recv(raw, buf, sizeof(buf), 0); if (rd == -1) err(1, "recv()"); if (handle_data(dude, buf, rd) == -1) return; } }
ssize_t my_write_proc(struct file *file,char *buf,size_t count,loff_t *ppos){ struct policy pol; int size=sizeof(struct policy); if(count>size){ count=size; } if(copy_from_user(&pol,buf,size)){ return -EFAULT; } printk("In the write function %d\n",pol.uid); handle_data(&pol); print_list(&root); return size; }
/*! \brief Windows reader thread. Runs continuously once port is open to a working device. This is a strict timeout blocking read due to windows's absolutelybraindead I/O model where select/poll isn't allowed on anything but network sockets. Overallpaed I/O is just too ugly... \param data is the encapsulation of the port filedescriptor \returns NULL on termination */ void *win32_reader(gpointer data) { gint fd = (GINT)data; gint errcount = 0; static gsize wanted = 2048; gboolean res = FALSE; gchar buf[2048]; gchar *ptr = NULL; gsize requested = 2048; gssize received = 0; gsize read_pos = 0; GIOStatus status; GError *err = NULL; GCond *cond = NULL; ENTER(); cond = (GCond *)DATA_GET(global_data,"serial_reader_cond"); while (TRUE) { if ((DATA_GET(global_data,"leaving")) || (DATA_GET(global_data,"serial_abort"))) { if (cond) g_cond_signal(cond); g_thread_exit(0); } read_pos = requested-wanted; received = read(fd, &buf[read_pos], wanted); g_usleep(10000); /*printf("Want %i, got %i,",wanted, received); */ if (received == -1) { DATA_SET(global_data,"connected",GINT_TO_POINTER(FALSE)); g_cond_signal(cond); g_thread_exit(0); } wanted -= received; /* printf("Still need %i\n",wanted); */ if (wanted <= 0) wanted = 2048; /*printf("WIN32 read %i bytes\n",received);*/ if (received > 0) handle_data((guchar *)buf+read_pos,received); g_cond_signal(cond); } EXIT(); return NULL; }
int Logging_Server::run (int argc, char *argv[]) { if (open (argc > 1 ? atoi (argv[1]) : 0) == -1) return -1; for (;;) { if (wait_for_multiple_events () == -1) return -1; if (handle_connections () == -1) return -1; if (handle_data () == -1) return -1; } return 0; }
int main(int argc, char** argv) { data_init(); network_init(); while (1) { post_receive_data(); if (wait_receive_data()) { printf("Warning: receive data failed\n"); continue; } handle_data(); send_ack(); } network_release(); data_release(); }
/*----------------------------------------------------------------------------*/ void handle_packet(packet_t* p) { if (p->info.rssi >= conf.rssi_min && p->header.net == conf.my_net){ if (p->header.typ == BEACON){ PRINTF("[PHD]: Beacon\n"); handle_beacon(p); } else { if (is_my_address(&(p->header.nxh))){ switch (p->header.typ){ case DATA: PRINTF("[PHD]: Data\n"); handle_data(p); break; case RESPONSE: PRINTF("[PHD]: Response\n"); handle_response(p); break; case OPEN_PATH: PRINTF("[PHD]: Open Path\n"); handle_open_path(p); break; case CONFIG: PRINTF("[PHD]: Config\n"); handle_config(p); break; default: PRINTF("[PHD]: Request/Report\n"); handle_report(p); break; } } } } else { packet_deallocate(p); } }
int server_loop(int request_sock) { int i, num_fds; fd_set read_fds; read_fds = master_fds; printf("Now waiting for data...\n"); num_fds = select(select_max_fds, &read_fds, NULL, NULL, &timeout); printf("Select returned! Got activity on %d sockets.\n", num_fds); if (num_fds < 0) { perror("select"); return -1; } if (num_fds == 0) { /* Select timed out. Shut down server. */ return -2; } for (i = 0; i < select_max_fds; i++) { if (FD_ISSET (i, &read_fds)) { if (i == request_sock) { /* Event on server socket. * There is a new incoming connection */ if(numsocks >= maxsocks) { fprintf(stderr, "No more space for sockets.\n"); return -1; } handle_new_connection(request_sock); } else { /* Event on existing client socket. */ handle_data(i); } } } return 0; }
void capiconn_inject(unsigned applid, unsigned char *msg) { capiconn_context *ctx = find_context(applid); if (!ctx) return; capi_message2cmsg(&s_cmsg, msg); if (s_cmsg.Command == CAPI_DATA_B3 && s_cmsg.Subcommand == CAPI_IND) { handle_data(ctx, &s_cmsg); ctx->nrecvdatapkt++; return; } if ((s_cmsg.adr.adrController & 0xffffff00) == 0) handle_controller(ctx, &s_cmsg); else if ((s_cmsg.adr.adrPLCI & 0xffff0000) == 0) handle_plci(ctx, &s_cmsg); else handle_ncci(ctx, &s_cmsg); ctx->nrecvctlpkt++; }
int Logging_Server::run(int argc, char** argv) { if (-1 == open(argc > 1 ? atoi(argv[1]) : 0)) { return -1; } while(1) { if (-1 == wait_for_multiple_events()) return -1; if (-1 == handle_connections()) return -1; if (-1 == handle_data()) return -1; } return 0; }
/*---------------------------------------------------------------------------*/ static void recv_ipolite(struct ipolite_conn *ipolite, const rimeaddr_t *from) { struct rudolph1_conn *c = (struct rudolph1_conn *) ((char *)ipolite - offsetof(struct rudolph1_conn, ipolite)); struct rudolph1_datapacket *p = packetbuf_dataptr(); PRINTF("%d.%d: Got ipolite type %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], p->h.type); c->nacks++; if(p->h.type == TYPE_NACK) { PRINTF("%d.%d: Got NACK for %d:%d (%d:%d)\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], p->h.version, p->h.chunk, c->version, c->chunk); if(p->h.version == c->version) { if(p->h.chunk < c->chunk) { /* Format and send a repair packet */ PRINTF("%d.%d: sending repair for chunk %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], p->h.chunk); format_data(c, p->h.chunk); ipolite_send(&c->ipolite, REPAIR_TIMEOUT, sizeof(struct rudolph1_hdr)); } } else if(LT(p->h.version, c->version)) { format_data(c, 0); ipolite_send(&c->ipolite, c->send_interval / 2, sizeof(struct rudolph1_hdr)); } } else if(p->h.type == TYPE_DATA) { /* This is a repair packet from someone else. */ PRINTF("%d.%d: got repair for chunk %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], p->h.chunk); handle_data(c, p); } }
/* * Handle HIL interrupts. */ static irqreturn_t hil_interrupt(int irq, void *handle, struct pt_regs *regs) { unsigned char s, c; s = hil_status(); c = hil_read_data(); switch (s >> 4) { case 0x5: handle_status(s, c); break; case 0x6: handle_data(s, c); break; case 0x4: hil_dev.s = s; hil_dev.c = c; mb(); hil_dev.valid = 1; break; } return IRQ_HANDLED; }
int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, uint32_t length) { if (length > MAX_DATA_SIZE) return 1; uint8_t public_key[crypto_box_PUBLICKEYBYTES]; uint8_t data[MAX_DATA_SIZE]; uint8_t number; int len = handle_request(chat->self_public_key, chat->self_secret_key, public_key, data, &number, packet, length); if (len <= 0) return 1; if (id_equal(chat->self_public_key, public_key)) return 1; int peernum = peer_in_chat(chat, public_key); if (peernum == -1) return 1; switch (number) { case CRYPTO_PACKET_GROUP_CHAT_GET_NODES: return handle_getnodes(chat, source, peernum, data, len); case CRYPTO_PACKET_GROUP_CHAT_SEND_NODES: return handle_sendnodes(chat, source, peernum, data, len); case CRYPTO_PACKET_GROUP_CHAT_BROADCAST: return handle_data(chat, data, len); default: return 1; } return 1; }
static void handle_accept(uint32_t events) { if (events != EPOLLIN) { syslog(LOG_ERR, "unexpected event on listening socket: %u\n", (unsigned)events); exit(1); } int fd = accept4(listen_fd, NULL, NULL, SOCK_CLOEXEC); if (fd < 0) { syslog(LOG_WARNING, "accept4: %s\n", strerror(errno)); return; } FILE *file = fdopen(fd, "r+"); if (!file) { syslog(LOG_WARNING, "fdopen: %s\n", strerror(errno)); close(fd); return; } char command[1024]; bool ok = fgets(command, sizeof(command), file); if (!ok || !command[0] || !feof(file)) { fclose(file); return; } fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); provider_t *p = get_provider(command); if (!p) { fclose(file); return; } add_client(p, file); handle_data(p); }
int main(void) { uint8_t data; static uint16_t checksum; uint8_t buffer[MAX_DATA_LEN] = {0}; int cur=0; int device; uint8_t datalen1; short data_len; enum Recstate //状态机 { RECFF1,RECFF2,SENDID,RECID,RECLEN1,RECLEN2,RECSEL,RECCHECK } rs485Recstate = RECFF1; /******************* 初始化 ******************/ init(); while(1) { if(queue_empty(rx_queue)) continue; data = (uint8_t)queue_get(&rx_queue); switch (rs485Recstate) { case RECFF1: if (data == 0xff) { rs485Recstate = RECFF2; checksum=0; cur = 0; //校验位清零 } break; case RECFF2: if (data == 0xff) rs485Recstate = RECID; else rs485Recstate = RECFF1; break; case RECID: if(data==0x01) //设备编号0x01底盘与航迹 { device=1; checksum += data; rs485Recstate = RECLEN1; } else rs485Recstate = RECFF1; break; case RECLEN1: checksum += data; datalen1 = data; rs485Recstate = RECLEN2; break; case RECLEN2: checksum += data; data_len = (short)datalen1 << 8 | data; rs485Recstate = RECSEL; break; case RECSEL: checksum += data; buffer[cur++] = data; if(cur >= data_len) rs485Recstate = RECCHECK; break; case RECCHECK: checksum=checksum%255; if(data == checksum) { handle_data(buffer,device, data_len); send(); checksum=0; rs485Recstate = RECFF1; } else rs485Recstate = RECFF1; break; default: rs485Recstate = RECFF1; } } }
static int8_t fetcher_handler(void *state, Message *msg) { switch (msg->type) { case MSG_FETCHER_FRAGMENT: { fetcher_fragment_t *f; f = (fetcher_fragment_t*)msg->data; f->key = entohs( f->key ); f->frag_id = entohs(f->frag_id); DEBUG_PID(KER_FETCHER_PID,"MSG_FETCHER_FRAGMENT:\n"); handle_overheard_fragment(msg); if(fst == NULL) { DEBUG_PID(KER_FETCHER_PID, "NO Request!!!\n"); return SOS_OK; //!< no request } //DEBUG_PID(KER_FETCHER_PID,"calling restart_request_timer()\n"); restart_request_timer(); fst->retx = 0; //DEBUG_PID(KER_FETCHER_PID,"calling handle_data()\n"); return handle_data(msg); } case MSG_FETCHER_REQUEST: { fetcher_bitmap_t *bmap = (fetcher_bitmap_t *) msg->data; bmap->key = entohs( bmap->key ); //! received request from neighbors DEBUG("handling request to %d from %d\n", msg->daddr, msg->saddr); if(msg->daddr == ker_id()) { return handle_request(msg); } if(fst == NULL) return SOS_OK; //!< no request restart_request_timer(); fst->retx = 0; return SOS_OK; } case MSG_TIMER_TIMEOUT: { MsgParam *params = (MsgParam*)(msg->data); if(params->byte == FETCHER_REQUEST_TID) { //DEBUG("request timeout\n"); if( no_mem_retry ) { send_fetcher_done(); return SOS_OK; } handle_request_timeout(); } else if(params->byte == FETCHER_TRANSMIT_TID) { //DEBUG("send fragment timeout\n"); if( send_state.num_msg_in_queue < FETCHER_MAX_MSG_IN_QUEUE ) { send_fragment(); } } return SOS_OK; } case MSG_PKT_SENDDONE: { if( send_state.num_msg_in_queue > 0 ) { send_state.num_msg_in_queue--; } return SOS_OK; } #ifdef SOS_HAS_EXFLASH case MSG_EXFLASH_WRITEDONE: { ker_free(send_state.fragr); send_state.fragr = NULL; check_map_and_post(); return SOS_OK; } case MSG_EXFLASH_READDONE: { post_auto(KER_FETCHER_PID, KER_FETCHER_PID, MSG_FETCHER_FRAGMENT, sizeof(fetcher_fragment_t), send_state.frag, SOS_MSG_RELEASE, send_state.dest); send_state.frag = NULL; return SOS_OK; } #endif case MSG_INIT: { send_state.map = NULL; send_state.frag = NULL; send_state.fragr = NULL; send_state.num_msg_in_queue = 0; ker_msg_change_rules(KER_FETCHER_PID, SOS_MSG_RULES_PROMISCUOUS); ker_permanent_timer_init(&(send_state.timer), KER_FETCHER_PID, FETCHER_TRANSMIT_TID, TIMER_REPEAT); ker_timer_init(KER_FETCHER_PID, FETCHER_REQUEST_TID, TIMER_ONE_SHOT); return SOS_OK; } } return -EINVAL; }
static void kbd_int_handler(int irq, void *dev_id, struct pt_regs *regs) { struct cir_port *cir; int j; unsigned char int_status; cir = (struct cir_port *)dev_id; int_status = get_int_status(cir);; if (int_status & 0x4) { clear_fifo(cir); return; } while (cir_get_rx_count(cir)) { cir_data[data_index] = cir_read_data(cir); if (data_index == 0) {/* expecting first byte */ if (cir_data[data_index] != leading1) { //printk("!leading byte %x\n", cir_data[data_index]); set_rx_active(cir); clear_fifo(cir); continue; } } if (data_index == 1) { if ((cir_data[data_index] & 0xf) != leading2) { set_rx_active(cir); data_index = 0; /* start over */ clear_fifo(cir); continue; } } if ( (cir_data[data_index] == 0xff)) { /* last byte */ //printk("data_index %d\n", data_index); set_rx_active(cir); #if 0 for (j=0; j<=data_index; j++) { printk("rx_data %d: %x\n", j, cir_data[j]); } #endif data_index = 0; handle_data(cir_data); return; } else if (data_index>16) { set_rx_active(cir); #if 0 printk("warning: data_index %d\n", data_index); for (j=0; j<=data_index; j++) { printk("rx_data %d: %x\n", j, cir_data[j]); } #endif data_index = 0; clear_fifo(cir); return; } data_index++; } }
static void handle_d32(char *s) { handle_data(s,32); }