void xdccd::IRCConnection::read(const boost::system::error_code& error, std::size_t count) { if (!error) { timeout_lock.lock(); message_received = true; timeout_lock.unlock(); bytes_read += count; // We succesfully received a message, reset reconnect timer reconnect_delay = xdccd::connection::MIN_RECONNECT_DELAY; boost::asio::streambuf::const_buffers_type bufs = msg_buffer.data(); read_handler( std::string(boost::asio::buffers_begin(bufs), boost::asio::buffers_begin(bufs) + count - 2) ); msg_buffer.consume(count); socket->async_read_until( msg_buffer, "\r\n", boost::bind(&IRCConnection::read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) ); } else { BOOST_LOG_TRIVIAL(error) << "Read error: " << error.message(); start_reconnect_timer(); } }
int sh1_read(void) { char c[4]; int ret; int key; t_win *term; term = g_memory(S_WIN, 0); if (initialize_read(term) == -1 || test_caps() == -1) return (-1); while (42) { ft_bzero(c, 4); if ((ret = read(STDIN_FILENO, c, 4)) < 0) return (int_error(EUNKNOW)); key = (c[3] << 24) + (c[2] << 16) + (c[1] << 8) + c[0]; ret = read_handler(term, key); if (ret == -1) return (-1); if (ret == ENDOF) return (end_of_read(term) == -1 ? -1 : 0); if (ret == RELAUNCH) if (relaunch_read(term) == -1) return (-1); } return (0); }
/** * Sets the reading flag to false and returns the handler that should be * called back with the result of the read. The cursor position that is sent * is whatever the value of m_cursor is. * * It MUST NOT be called when m_reading is false. * it MUST be called while holding the read lock * * It is important to use this method rather than directly setting/calling * m_read_handler back because this function makes sure to delete the * locally stored handler which contains shared pointers that will otherwise * cause circular reference based memory leaks. * * @param ec The error code to forward to the read handler */ void complete_read(lib::error_code const & ec) { m_reading = false; read_handler handler = m_read_handler; m_read_handler = read_handler(); handler(ec,m_cursor); }
static int read_string_handler(void *arg, const char *k, uuid *v) { hlinda *h = (hlinda*)arg; if (strcmp(k, h->string_id)) return 0; return read_handler(arg, (void*)(size_t)k, v); }
static int read_int_handler(void *arg, int64_t k, uuid *v) { hlinda *h = (hlinda*)arg; if (k != h->int_id) return 0; return read_handler(arg, (void*)(size_t)k, v); }
void turbulence_loop_handle_descriptors (TurbulenceLoop * loop) { TurbulenceLoopDescriptor * loop_descriptor; TurbulenceLoopOnRead read_handler; axlPointer ptr; axlPointer ptr2; /* reset cursor */ axl_list_cursor_first (loop->cursor); while (axl_list_cursor_has_item (loop->cursor)) { /* get loop descriptor */ loop_descriptor = axl_list_cursor_get (loop->cursor); /* check if the loop descriptor is set */ if (__vortex_io_waiting_default_is_set (loop_descriptor->descriptor, loop->fileset, NULL)) { /* reset handlers and user pointers */ read_handler = NULL; ptr = NULL; ptr2 = NULL; /* configure the read handler to be used. If it is defined the default handler use it */ if (loop->on_read != NULL) { read_handler = loop->on_read; ptr = loop->ptr; ptr2 = loop->ptr2; } /* in the case a particular on read handler is defined, use it instead of default one */ if (loop_descriptor->on_read != NULL) { read_handler = loop_descriptor->on_read; ptr = loop_descriptor->ptr; ptr2 = loop_descriptor->ptr2; } /* call to notify descriptor (if no handler close descriptor to avoid infinite loops) */ if (read_handler == NULL || (! read_handler (loop, loop->ctx, loop_descriptor->descriptor, ptr, ptr2))) { /* function returned axl_false, remove descriptor from watch set */ axl_list_cursor_remove (loop->cursor); continue; } /* end if */ } /* end if */ /* get the next item */ axl_list_cursor_next (loop->cursor); } /* end if */ return; }
/*Thread Function * INPUT: * void *parameter : Connection Identifier */ void *thread_fun (void *parameter) { char recvBuff[1024] , len[5] , data[500]; int p_size , res , conn = 0 , st = 0; /*Connection Identifier */ conn = *(int *)parameter; /*Loops till the File is closed */ while (st == 0) { /*Clear the Buffer content */ memset (recvBuff , 0 , sizeof (recvBuff)); /*Receive marshalled data sent by Client*/ p_size = read (conn , recvBuff , sizeof (recvBuff) - 1); if (p_size != 0) { recvBuff[p_size] = 0; memset (data , 0 , sizeof (data)); memcpy (data , &recvBuff , 3); res = atoi (data); /*Interprete received data based on type of call */ switch (res) { case _r_list: st = list_handler (conn); break; case _r_open: st = open_handler (conn , recvBuff); break; case _r_read: st = read_handler (conn , recvBuff); break; case _r_write: st = write_handler (conn , recvBuff); break; case _r_close: st = close_handler (conn , recvBuff); break; } } } out: return; }
static void syscall_handler(struct intr_frame *f) { void *esp = f->esp; thread_current()->saved_esp = f->esp; // printf("$esp = %p\n",esp); byte_access_ok(esp,false); // hex_dump(esp, esp,16,true); // printf("\n"); int sys_call_num = *(int*) esp; esp += sizeof(int *); byte_access_ok(esp,false); // printf("$sys_call_num = %p\n",sys_call_num); char* argv[5]; switch (sys_call_num) { /* Projects 2 and later. */ //TODO: please retrieve parameters from the stack // and pass them to the handlers. case SYS_HALT: /* Halt the operating system. */ halt_handler(); break; case SYS_EXIT: /* Terminate this process. */ parse_arg(esp, 1, argv); exit_handler((int) argv[0]); break; case SYS_EXEC: /* Start another process. */ parse_arg(esp, 1, argv); f->eax=exec_handler((void*)argv[0]); break; case SYS_WAIT: /* Wait for a child process to die. */ parse_arg(esp, 1, argv); f->eax=wait_handler((int) argv[0]); break; case SYS_CREATE: /* Create a file. */ parse_arg(esp, 2, argv); f->eax=create_handler((void*)argv[0], (unsigned) argv[1]); break; case SYS_REMOVE: /* Delete a file. */ parse_arg(esp, 1, argv); f->eax=remove_handler((void*)argv[0]); break; case SYS_OPEN: /* Open a file. */ parse_arg(esp, 1, argv); f->eax=open_handler((void*)argv[0]); break; case SYS_FILESIZE: /* Obtain a file's size. */ parse_arg(esp, 1, argv); f->eax=filesize_handler((int) argv[0]); break; case SYS_READ: /* Read from a file. */ parse_arg(esp, 3, argv); f->eax=read_handler((int) argv[0], (void*) argv[1], (unsigned) argv[2]); break; case SYS_WRITE: /* Write to a file. */ parse_arg(esp, 3, argv); f->eax=write_handler((int) argv[0], (void*) argv[1], (unsigned) argv[2]); break; case SYS_SEEK: /* Change position in a file. */ parse_arg(esp, 2, argv); seek_handler((int) argv[0], (unsigned) argv[1]); break; case SYS_TELL: /* Report current position in a file. */ parse_arg(esp, 1, argv); f->eax=tell_handler((int) argv[0]); break; case SYS_CLOSE: /* Close a file. */ parse_arg(esp, 1, argv); close_handler((int) argv[0]); break; case SYS_MMAP: parse_arg(esp, 2, argv); f->eax=mmap_handler ((int) argv[0], (void*)argv[1]); break; case SYS_MUNMAP: parse_arg(esp, 1, argv); munmap_handler ((mapid_t) argv[0]); break; default: printf("system call %d not implemented!\n", sys_call_num); } //thread_exit(); }
int main(void) { char *perr = NULL; void* dl_lib_handler; FUNC_READ read_handler; FUNC_WRITE write_handler; void* dl_lib_handler2; FUNC_READ read_handler2; FUNC_WRITE write_handler2; printf("open [%s] . . . ", DL_TEST); /*open so 1*/ dl_lib_handler = dlopen(DL_TEST, RTLD_LAZY); if(!dl_lib_handler) { printf("failed \n"); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); } return 0; } printf("success\n"); printf("open [%s] . . . ", DL_TEST2); /*open so 2*/ dl_lib_handler2 = dlopen(DL_TEST2, RTLD_LAZY); if(!dl_lib_handler2) { printf("failed \n"); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); } return 0; } printf("success\n"); /*get read/write in so 1*/ read_handler = (FUNC_READ)dlsym(dl_lib_handler, DL_TEST_READ); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); goto closelib; } write_handler = (FUNC_READ)dlsym(dl_lib_handler, DL_TEST_WRITE); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); goto closelib; } /*get read/write in so 2*/ read_handler2 = (FUNC_READ)dlsym(dl_lib_handler2, DL_TEST_READ2); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); goto closelib; } write_handler2 = (FUNC_READ)dlsym(dl_lib_handler2, DL_TEST_WRITE2); perr = dlerror(); if(NULL != perr) { printf("%s\n", perr); goto closelib; } /*read global var in so 1/2*/ read_handler(); read_handler2(); /*2 W -> 1 R*/ write_handler2(999); read_handler(); /*1 W -> 2 R*/ write_handler(555); read_handler2(); closelib: if(!dl_lib_handler) dlclose(dl_lib_handler); if(!dl_lib_handler2) dlclose(dl_lib_handler2); return 0; }
int main(int argc, char *argv[]) { int stcp = -1; int sudp = -1; int rc = -1; if (argc != 2) { fprintf(stderr, "Usage: %s [port]\n", argv[0]); exit(1); } /* Limit memory usage by SQLite to a reasonable, relatively small level. */ #ifdef WWDEBUG printf("Current SQLite heap size limit is %ld. Setting it to 8MB.\n", sqlite3_soft_heap_limit(-1)); #endif sqlite3_soft_heap_limit(8*1024*1024); #ifdef WWDEBUG printf("New SQLite heap size limit is %ld.\n", sqlite3_soft_heap_limit(-1)); #endif /* Include this only if we are *not* compiling a debug version */ #ifndef WWDEBUG /* Fork and background (basically) */ pid_t pid = fork(); if (pid != 0) { if (pid < 0) { perror("AGGREGATOR: Failed to fork"); exit(1); } exit(0); } #endif bzero(sock_data, sizeof(sock_data)); // Get the database ready // Attempt to open database & check for failure #ifdef WWDEBUG printf("Attempting to open database: %s\n", SQLITE_DB_FNAME); #endif rc = sqlite3_open(SQLITE_DB_FNAME, &db); if (rc) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } else { // Now check & create tables if required createTable(db, 1); createTable(db, 2); #ifdef WWDEBUG printf("Database ready for reading and writing...\n"); #endif } // Prepare to accept clients FD_ZERO(&rfds); FD_ZERO(&wfds); // Open TCP (SOCK_STREAM) & UDP (SOCK_DGRAM) sockets, bind to the port // given and listen on TCP sock for connections if ((setup_sockets(atoi(argv[1]), &stcp, &sudp)) < 0) { perror("WWAGGREGATOR: Error setting up Sockets\n"); exit(1); } #ifdef WWDEBUG printf("Our listen sock # is - %d & UDP sock # is - %d \n", stcp, sudp); #endif //printf("FD_SETSIZE - %d\n",FD_SETSIZE); //Add the created TCP & UDP sockets to the read set of file descriptors FD_SET(stcp, &rfds); FD_SET(sudp, &rfds); // Event loop while (1) { int n = 0; fd_set _rfds, _wfds; memcpy(&_rfds, &rfds, sizeof(fd_set)); memcpy(&_wfds, &wfds, sizeof(fd_set)); // Block until there's an event to handle // Select function call is made; return value 'n' gives the number of FDs ready to be serviced if (((n = select(FD_SETSIZE, &_rfds, &_wfds, NULL, 0)) < 0) && (errno != EINTR)) { perror("select"); exit(1); } // Handle events for (int i = 0; (i < FD_SETSIZE) && n; i++) { if (FD_ISSET(i, &_rfds)) { // Handle our main mother, TCP listening socket differently if (i == stcp) { if (accept_conn(stcp) < 0) exit(1); // Handle our UDP socket differently } else if (i == sudp) { read_and_dump_data(sudp); } else { #ifdef WWDEBUG fprintf(stderr, "File descriptor %d is ready for reading .. call'g readHLR\n", i); #endif read_handler(i); } n--; } if (FD_ISSET(i, &_wfds)) { #ifdef WWDEBUG fprintf(stderr, "File descriptor %d is ready for writing .. call'g writeHLR\n", i); #endif write_handler(i); n--; } } } }
int main(int argc, char* argv[]) { int pid; Msg myMsg; int sender_pid; initialize(); if (Register(FILE_SERVER)) { perror("Register server process error!"); } if (argc>1) { pid = Fork(); if (pid==0) { Exec(argv[1],argv+1); } } while (1) { if ((sender_pid=Receive(&myMsg))==ERROR) { // perror("error receiving message!"); continue; } switch (myMsg.type) { case OPEN: open_handler(&myMsg,sender_pid);break; /* case CLOSE: close_handler(&myMsg,sender_pid);break; */ case CREATE: create_handler(&myMsg,sender_pid);break; case READ: read_handler(&myMsg,sender_pid);break; case WRITE: write_handler(&myMsg,sender_pid);break; /* case SEEK: seek_handler(&myMsg,sender_pid);break; */ case LINK: link_handler(&myMsg,sender_pid);break; case UNLINK: unlink_handler(&myMsg,sender_pid);break; case SYMLINK: symlink_handler(&myMsg,sender_pid);break; case READLINK: readlink_handler(&myMsg,sender_pid);break; case MKDIR: mkdir_handler(&myMsg,sender_pid);break; case RMDIR: rmdir_handler(&myMsg,sender_pid);break; case CHDIR: chdir_handler(&myMsg,sender_pid);break; case STAT: stat_handler(&myMsg,sender_pid);break; case SYNC: sync_handler(&myMsg);break; case SHUTDOWN: shutdown_handler(&myMsg,sender_pid);break; default: perror("message type error!"); break; } if (Reply(&myMsg,sender_pid)==ERROR) fprintf(stderr, "Error replying to pid %d\n",sender_pid); } terminate(); return 0; }
int rf_epoll_wait(epoll_handle_accept *accept_handler,epoll_handle_read_event *read_handler,epoll_handle_write_event *write_handler){ int nfds; int i; rf_client *rfc; nfds = epoll_wait(kdpfd, events, MAX_EVENTS, EPOLL_TIMEOUT); if(nfds == -1) { if( errno != EINTR ) { cclog(2,"ERROR. {%s}\n", strerror(errno)); return RF_ERR_EPOLL; } return RF_OK; } else if( 0 == nfds) { cclog(9,"epoll timeout!"); return RF_OK; } int ret = -1; int fd; for( i = 0 ; i < nfds ; i++ ) { if( listen_fd == events[i].data.fd ) { accept_handler(listen_fd); continue; } fd = events[i].data.fd; rfc = &fd_table[fd]; if(events[i].events & (EPOLLIN|EPOLLHUP|EPOLLERR)){ ret = read_handler(fd); switch(ret){ case RF_OK: cclog(5,"process success! fd(%d)",fd); break; case RF_ERR_PEER_CLOSE: cclog(2,"close peer socket! close fd(%d),ip(%s)",fd,get_peer_ip(fd)); //add for async report dir refresh result if(rfc->type == RF_CLIENT_REPORT) { rf_set_session_report_status(fd, RF_SESSION_CLOSE); } //add for async report dir refresh result disconnect_fd(fd); break; case RF_CLOSE_REPORT: if(rfc->type == RF_CLIENT_REPORT) { cclog(2, "refreshd close report fd: [%d], peer_ip: [%s]", fd, get_peer_ip(fd)); rf_set_session_report_status(fd, RF_SESSION_SUCCESS); } disconnect_fd(fd); break; default: //add for async report dir refresh result if(rfc->type == RF_CLIENT_REPORT) { rf_set_session_report_status(fd, RF_SESSION_FAILED); } //add for async report dir refresh result cclog(2,"proccess error! close fd(%d),ip(%s),ret(%d)",fd,get_peer_ip(fd),ret); disconnect_fd(fd); break; } } if(events[i].events & (EPOLLOUT|EPOLLHUP|EPOLLERR)){ ret = write_handler(fd); switch(ret){ case RF_OK: cclog(5,"process success! fd(%d),ip(%s)",fd,get_peer_ip(fd)); break; case RF_ERR_PEER_CLOSE: cclog(2,"close peer socket! close fd(%d),ip(%s)",fd,get_peer_ip(fd)); //add for async report dir refresh result if(rfc->type == RF_CLIENT_REPORT) { rf_set_session_report_status(fd, RF_SESSION_SUCCESS); } //add for async report dir refresh result disconnect_fd(fd); break; default: //add for async report dir refresh result rfc = &fd_table[fd]; if(rfc->type == RF_CLIENT_REPORT) { rf_set_session_report_status(fd, RF_SESSION_FAILED); } //add for async report dir refresh result cclog(2,"proccess error! close fd(%d),ip(%s)",fd,get_peer_ip(fd)); disconnect_fd(fd); break; } } } return RF_OK; }
void main() { init(0x00); /* wait EFM32 to choose a partition or ATA password is supported*/ #ifdef GPIO_security GPIO_security_init(); //security_nd_chk = security_cmd_info_read(scl_security_nd_chk);//security function need or not //myprintf("\nsysmode:%c",security_nd_chk); //while(/*(security_nd_chk=='Y') && */(!g_security_enable) && (security_mode !=show_master) && (security_mode !=show_user) && (security_mode !=show_all)) // { // GPIO_security_cmd(1); // myprintf("\nwait chk"); // uart_show=0x1; // } //init(); #endif while(1) { #ifdef SUPER_ERASE #ifdef GPIO_security if((security_mode !=show_master) && (security_mode !=show_user) && (security_mode !=show_all)) { g_security_lock=1; GPIO_security_cmd(0x01); } else { g_security_lock=0; if(g_SYS_YD==0x01) { GPIO_security_cmd(0x00); } else { //myprintf("\nwhile erase"); GPIO_security_cmd(0x01); } } #endif if((security_erase==show_master) ||(security_erase==show_user)) { security_cmd_info_write('N', scl_security_nd_chk);//need reconfig myprintf("\nes0"); intial_data_partition(0);//erase partition security_erase=0x00; myprintf("\ned0"); } else if(security_erase==show_all) { security_cmd_info_write('N', scl_security_nd_chk);//need reconfig myprintf("\nes0"); intial_data_partition(1);//erase partition security_erase=0x00; myprintf("\ned1"); } if(uart_show) { if(security_mode == show_master) { myprintf("\nmaster mode"); uart_show=0; } else if(security_mode == show_user) { myprintf("\nuser mode"); uart_show=0; } else if(security_mode == show_all) { myprintf("\nzsd mode"); uart_show=0; } tx_fis_A1(status_good, error_no, int_set); init(0x01); } #endif #ifdef security_debug myprintf("\rSV:%x",SFR_spi_io); #endif #ifdef BUF_CMD_EN //todo: if NCQ error, need additional control here??? cmd_buffer_check(); #endif //check new fis received from host(exclude data fis) //sata.led0_cntl = 0x80; //rom is using 0xd4 if(g_current_fis_num != SFR_fis_num) { //sata.led0_cntl = 0x00; //rom is using 0xd4 sata.led0_blink = 0x44; //myprintf("\nSR0:%x",SFR_FIS0_1); //todo: add an led1 here. //myprintf("\nfine a new cmd:%x",SFR_FIS0_2); g_current_fis_num = SFR_fis_num; //clear the fis27 flag. sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27)); //if in SLEEP mode, only respond to SRST. Please refer to ATA8 Charpter 7.55.2 //TODO: need to open this after this is tested. //if(g_power_mode == power_mode_sleep)goto check_control; #ifdef SUPPORT_NCQ if(g_ncq_halt) { if(check_ncq_read_log); //else goto Over; else continue; } #endif //open the CHP clock chp_clock_on(); #ifdef SUPPORT_SMART1 if(g_smart_power_down_flag == 1) { updata_smart(smart_power_down_addr,0x01); g_smart_power_down_flag = 0; reset_engine(); } #endif //this will load the sector count check_sec_cnt(); //myprintf("\nsec_cnt:%x",g_sec_cnt.byte.l); check_lba(); //myprintf("\nLBAchk0:%x"); if(SFR_quick_cmd!=0) { #ifdef SUPPORT_SECURITY //analyze_states(); g_security_prepared = 0; if(g_security_lock == 1) { tx_fis_34(status_bad, error_abort,int_set); } else #endif { #ifdef BUF_CMD_EN if(SFR_quick_cmd & quick_cmd_write_dma) { //break buffer command flow: //(1)continue command //(2)chs mode command //(3)counter > threshold if(check_chs_cmd) { if(buf_not_empty) g_current_fis_num--; else { chs_write_handle(); buf_check_cnt = 0x00; } } else if(normal_cmd_cont || (g_sec_cnt.word == 0x0000) || (g_sec_cnt.byte.h!=0x00) || (g_sec_cnt.byte.l >BUF_SEC_CNT_THRESHOLD) ||(g_enable_write_cache == 0)) { if(buf_not_empty) g_current_fis_num--; else { write_handler(); buf_check_cnt = 0x00; } } else if(buf_check_cnt<BUF_START_CNT) { if(buf_not_empty) g_current_fis_num--; else { write_handler(); buf_check_cnt++; } } else { //check_lba(); //the if will not happen if(g_flag_lba_err) { tx_fis_34(status_bad,error_abort,int_set); reset_engine(); } else { buf_sector_num.word = 0; buf_cmd_flag = DEF_CHP_EN; cmd_buffer_set_param(); //TODO: add reset_engine here??? g_cont_en = 0; } } } //need to flush all data in FIFO before other commands else if(buf_not_empty)g_current_fis_num--; #else if(SFR_quick_cmd & quick_cmd_write_dma) { if(check_chs_cmd)chs_write_handle(); else write_handler(); } #endif //(2)this is read_dma or read_dma_ext else if(SFR_quick_cmd & quick_cmd_read_dma) { // myprintf("\nr"); if(check_chs_cmd)chs_read_handle(); else read_handler(); } else if(SFR_quick_cmd & (quick_cmd_write_mul | quick_cmd_write_sec)) { g_flag_dir = DIR_WRITE; pio_write_handler(); } //(4)read pio: read_sector([ext]) or read_multiple([ext]) //else if((SFR_quick_cmd&quick_cmd_read_mul) || (SFR_quick_cmd&quick_cmd_read_sec)); else if(SFR_quick_cmd & (quick_cmd_read_mul | quick_cmd_read_sec)) { g_flag_dir = DIR_READ; pio_read_handler(); } g_power_mode = power_mode_act; } } else if(SFR_FIS0_0 == 0x27)//this is H2D fis { #ifdef BUF_CMD_EN if(buf_not_empty)g_current_fis_num--; else if((SFR_FIS0_1 & 0x80) !=0) //this is a command, not control #else if((SFR_FIS0_1 & 0x80) !=0) //this is a command, not control #endif { #ifdef SUPPORT_SECURITY if(SFR_FIS0_2 != ata_security_erase_unit) g_security_prepared = 0; #endif if(SFR_FIS0_2 == ata_write_dma_fua_ext) { write_handler(); g_power_mode = power_mode_act; } else if(SFR_FIS0_2 == ata_write_multi_fua_ext) { g_flag_dir = DIR_WRITE; pio_write_handler(); g_power_mode = power_mode_act; } #ifdef SUPPORT_NCQ else if(SFR_FIS0_2 == ata_read_fpdma) { g_flag_dir = DIR_READ; ncq_resp_cmd(); g_power_mode = power_mode_act; } else if(SFR_FIS0_2 == ata_write_fpdma) { g_flag_dir = DIR_WRITE; ncq_resp_cmd(); g_power_mode = power_mode_act; } #endif else { reset_engine(); switch(SFR_FIS0_2)//this is the ata command index { //NCQ #ifdef SUPPORT_NCQ case ata_ncq_management: { ncq_management_hander(); g_power_mode = power_mode_act; break; } case ata_read_log_ext: { ncq_read_log(); g_power_mode = power_mode_act; break; } case ata_read_log_dma_ext: { ncq_read_log(); g_power_mode = power_mode_act; break; } #endif /////////////////////////////////////////////////// ///////////BASIC /////////////////////////////////////////////////// case ata_nop: { //note: sub-code is used for overlapped feature support. tx_fis_34(status_bad, error_abort,int_set); break; } case ata_seek: { //this is sent by host to signify the device that it may access the specified address in the following commands if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set); else tx_fis_34(status_good,error_no,int_set); g_power_mode = power_mode_act; break; } case ata_recalibrate: { //this is vendor specific - ATA4 tx_fis_34(status_good,error_no,int_set); break; } case ata_exec_diag: { init_tx_fis(); tx_fis_34(status_bad&0xf2,0x01,int_set); //0x01h indicated device0 passed and device1 not present break; } case ata_init_dev_para: { //this is to set CHS translation. //todo: change the setting of hardware operation: CHS translation. init_dev_para(); break; } case ata_flush_cache: { //TODO: flush the CHPs. //This command is used by the host to request the device to flush the write cache. If there is data in the write //cache, that data shall be written to the media. This command shall not indication completion until the data is //flushed to the media or an error occurs. //NOTE . This command may take longer than 30 s to complete. flush_delay(); tx_fis_34(status_good,error_no,int_set); g_power_mode = power_mode_act; break; } case ata_flush_cache_ext: { flush_delay(); tx_fis_34(status_good,error_no,int_set); g_power_mode = power_mode_act; break; } case ata_read_verify: //this command wasn't completed, the write protect error should be took into accout { if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set); else tx_fis_34(status_good,error_no,int_set); g_power_mode = power_mode_act; break; } case ata_read_verify_ext: //this command wasn't completed, the write protect error should be took into accout { if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set); else tx_fis_34(status_good,error_no,int_set); g_power_mode = power_mode_act; break; } #ifdef SUPPORT_SMART case ata_smart: { //myprintf("\nsmart_handler"); smart_handler(); break; } #endif case ata_data_set_management: { #ifdef SUPPORT_TRIM //#if 0 //if(check_sd_mode) tx_fis_34(status_good,error_no,int_set); //else if((sata.FIS_seccnt_ext !=0)||(sata.FIS_seccnt >0x20)||((sata.FIS_seccnt_ext==0)&&(sata.FIS_seccnt==0))) { tx_fis_34(status_good,error_no,int_set); } else trim_handler(); #else tx_fis_34(status_good,error_no,int_set); #endif break; } //////////////////////////////////////////////////// /////POWER MANAGEMENT FEATURE SET //////////////////////////////////////////////////// case ata_chk_power_mode: { sata.FIS_seccnt=g_power_mode; tx_fis_34(status_good,error_no,int_set); break; } case ata_idle: { flush_delay(); g_power_mode=power_mode_idle; tx_fis_34(status_good,error_no,int_set); break; } case ata_idle_imd: { flush_delay(); g_power_mode=power_mode_idle; tx_fis_34(status_good,error_no,int_set); break; } case ata_sleep: { flush_delay(); g_power_mode=power_mode_sleep; tx_fis_34(status_good,error_no,int_set); break; } case ata_standby: { flush_delay(); g_power_mode=power_mode_standby; tx_fis_34(status_good,error_no,int_set); break; } case ata_standby_imd: { flush_delay(); g_power_mode=power_mode_standby; tx_fis_34(status_good,error_no,int_set); break; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// case ata_identify_device: { identify_device(); break; } case ata_set_multiple: { if(sata.fis_rcv_content[4*3+0] == 0x01) { // we support transmitting 1 sector per multiple operation only, so the identify_data[59] low will not change /* identify_data[59] &= 0xff00; identify_data[59] |=0x0001; */ tx_fis_34(status_good,error_no,int_set); break; } else { tx_fis_34(status_bad,error_abort,int_set); break; } } case ata_set_feature: { set_feature(); //tx_fis_34(status_good,error_no,int_set); break; } case ata_security_freeze_lock: //ok { #ifdef SUPPORT_SECURITY if(g_security_lock == 1) { tx_fis_34(status_bad, error_abort,int_set); } else { if(g_security_enable == 0) security_state_flag = SEC2; else security_state_flag = SEC6; analyze_states(); tx_fis_34(status_good,error_no,int_set); } #else tx_fis_34(status_good,error_no,int_set); #endif break; } ////////////////////////////////////////////////// #ifdef SUPPORT_SECURITY case ata_security_erase_pre: /* BIOS没有权限擦除硬盘,所以直接返回 */ { if(g_security_frozen == 1) { g_security_prepared = 0; tx_fis_34(status_bad, error_abort,int_set); } else { //g_security_prepared = 1; // security_state_flag = SEC4; tx_fis_34(status_good,error_no,int_set); } //analyze_states(); break; } case ata_security_erase_unit: /* BIOS没有权限擦除硬盘,所以直接返回 */ { if(g_security_frozen == 1) { g_security_prepared = 0; tx_fis_34(status_bad, error_abort,int_set); } else { /*if(g_security_prepared == 0) g_security_abort = 1; else security_erase_unit(); if(g_security_abort == 1) { g_security_abort = 0; tx_fis_34(status_bad, error_abort,int_set); } else { g_security_prepared = 0; security_state_flag = SEC1;*/ tx_fis_34(status_good,error_no,int_set); /*} analyze_states();*/ } break; } case ata_security_dis_pwd: //ok { //此处删掉frozen下不能取消密码功能,dell 1014 进入bios的时候已经frozen了 if(/*(g_security_frozen == 1) ||*/ (g_security_lock == 1)) { g_security_prepared = 0; tx_fis_34(status_bad, error_abort,int_set); } else { security_dis_pwd(); if(g_security_abort == 1) { g_security_abort = 0; tx_fis_34(status_bad, error_abort,int_set); } else { security_state_flag = SEC1; tx_fis_34(status_good,error_no,int_set); } analyze_states(); } break; } case ata_security_set_pwd: //ok { if((g_security_frozen == 1) ) { g_security_prepared = 0; tx_fis_34(status_bad, error_abort,int_set); } else { security_set_pwd(); if(g_security_abort == 1) { g_security_abort = 0; tx_fis_34(status_bad, error_abort,int_set); } else tx_fis_34(status_good,error_no,int_set); analyze_states(); } break; } case ata_security_unlock: //ok { //analyze_states(); //myprintf("\nunlock"); security_unlock(); if(g_security_abort == 1) { g_security_abort = 0; tx_fis_34(status_bad, error_abort,int_set); } else { security_state_flag = SEC5; tx_fis_34(status_good,error_no,int_set); } analyze_states(); break; } #endif /////////////////////////////////////////////// #ifdef SUPER_ERASE case ata_down_microcode: { if(sata.FIS_feature == 0xCC)//super erase { intial_data_partition(1);//erase all // security_erase_pa(1); tx_fis_34(status_good,error_no,int_set); break; } else { tx_fis_34(status_bad, error_abort,int_set); break; } } #endif #ifdef READ_ONLY case ata_read_only: { choose_mode(); break; } #endif default : { tx_fis_34(status_bad, error_abort,int_set); break; } } } } else //control command process { #ifdef BUF_CMD_EN buf_data_pending = 0; #endif reset_engine(); //check_control: //IF SRST if((SFR_cmd_aux & 0x01)!=0) { //wait until SRST is deasserted. while((sata.fis_rcv_content[15] & 0x04)==0x04); //clear the fis27 flag. //sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27)); //hardware latch the SRST state, firmware clear it. SFR_cmd_aux = 0x00; g_current_fis_num = SFR_fis_num; //only resonse when SRST is not set } //also response the other controls without SRST bit set. if(g_power_mode != power_mode_sleep) { init_tx_fis(); //reset link(bit2) and transport(bit3). //if SRST, we may recover from abnormal state sata.rst_cntl = sata.rst_cntl | 0x0C; delay(5); sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27)); tx_fis_34(status_good,0x01,int_no); #ifdef SUPPORT_SMART1 updata_smart(smart_softrst_num_addr,0x01); reset_engine(); #endif } } } else if(SFR_FIS0_0 == 0x58) { bist_handler(); } SFR_watch_dog_high = 0x00; } else { //(1)if current loop has command, not handle DMA setup //(2)if current loop handle DMA setup, not send SET DEV BITS FIS //(3)otherwise send SET_DEV_BITS FIS #ifdef SUPPORT_NCQ ncq_handler(); #endif } #ifdef SUPPORT_SMART1 if(check_sd_mode) smart_card_crc(); else smart_block_handle(); #endif /* if(g_power_mode == power_mode_idle) { if(SFR_watch_dog_high >= 0x20) g_power_mode = power_mode_standby; } */ if((SFR_watch_dog_high > 0x30) && g_chp_active)chp_clock_off(); } }