static void udps_send_user(TCPIPS* tcpips, IP* src, IO* io, HANDLE handle) { IO* user_io; unsigned int offset, size; UDP_STACK* udp_stack; UDP_HANDLE* uh; UDP_HEADER* hdr = io_data(io); uh = so_get(&tcpips->udps.handles, handle); for (offset = sizeof(UDP_HEADER); uh->head && offset < io->data_size; offset += size) { user_io = udps_peek_head(tcpips, uh); udp_stack = io_push(user_io, sizeof(UDP_STACK)); udp_stack->remote_addr.u32.ip = src->u32.ip; udp_stack->remote_port = be2short(hdr->src_port_be); size = io_get_free(user_io); if (size > io->data_size - offset) size = io->data_size - offset; memcpy(io_data(user_io), (uint8_t*)io_data(io) + offset, size); user_io->data_size = size; io_complete(uh->process, HAL_IO_CMD(HAL_UDP, IPC_READ), handle, user_io); } #if (UDP_DEBUG) if (offset < io->data_size) printf("UDP: %d byte(s) dropped\n", io->data_size - offset); #endif //UDP_DEBUG }
static inline void lpc_sdmmc_verify(CORE* core) { SHA1_CTX sha1; uint8_t hash_in[SHA1_BLOCK_SIZE]; if ((core->sdmmc.state != SDMMC_STATE_VERIFY) && (core->sdmmc.state != SDMMC_STATE_WRITE_VERIFY)) return; sha1_init(&sha1); sha1_update(&sha1, io_data(core->sdmmc.io), core->sdmmc.total); sha1_final(&sha1, core->sdmmc.state == SDMMC_STATE_VERIFY ? hash_in : core->sdmmc.hash); if (core->sdmmc.state == SDMMC_STATE_WRITE_VERIFY) { core->sdmmc.state = SDMMC_STATE_VERIFY; lpc_sdmmc_prepare_descriptors(core); if (sdmmcs_read(&core->sdmmc.sdmmcs, core->sdmmc.sector, core->sdmmc.total / core->sdmmc.sdmmcs.sector_size)) return; } else { if (memcmp(core->sdmmc.hash, hash_in, SHA1_BLOCK_SIZE) == 0) { io_complete(core->sdmmc.process, HAL_IO_CMD(HAL_SDMMC, IPC_WRITE), core->sdmmc.user, core->sdmmc.io); core->sdmmc.io = NULL; core->sdmmc.process = INVALID_HANDLE; core->sdmmc.state = SDMMC_STATE_IDLE; return; } } io_complete_ex(core->sdmmc.process, HAL_IO_CMD(HAL_SDMMC, IPC_WRITE), core->sdmmc.user, core->sdmmc.io, get_last_error()); core->sdmmc.io = NULL; core->sdmmc.process = INVALID_HANDLE; core->sdmmc.state = SDMMC_STATE_IDLE; }
static inline void lpc_sdmmc_get_media_descriptor(CORE* core, HANDLE process, HANDLE user, IO* io) { STORAGE_MEDIA_DESCRIPTOR* media; if (!core->sdmmc.active) { error(ERROR_NOT_CONFIGURED); return; } if (user != core->sdmmc.user) { error(ERROR_INVALID_PARAMS); return; } media = io_data(io); media->num_sectors = core->sdmmc.sdmmcs.num_sectors; //SDSC/HC media->num_sectors_hi = 0; media->sector_size = core->sdmmc.sdmmcs.sector_size; sprintf(STORAGE_MEDIA_SERIAL(media), "%08X", core->sdmmc.sdmmcs.serial); io->data_size = sizeof(STORAGE_MEDIA_DESCRIPTOR) + 8 + 1; io_complete(process, HAL_IO_CMD(HAL_SDMMC, STORAGE_GET_MEDIA_DESCRIPTOR), core->sdmmc.user, io); error(ERROR_SYNC); }
static int io_run (io_context_t ctx, volatile unsigned *pending) { int ret; struct io_event e [5]; /* process iocbs so long as they reissue */ while (pending) { unsigned i; struct iocb *iocb; io_callback_t io_complete; /* wait for at least one event */ ret = io_getevents (ctx, 1, 5, &e [0], 0); if (ret < 0) break; for (i = 0; i < ret; i++) { io_complete = (io_callback_t) e [i].data; iocb = (struct iocb *)e [i].obj; io_complete (ctx, iocb, e [i].res, e [i].res2); } } return ret; }
bool io_run_append(const char **argv, int fd) { return io_complete(IO_AP, argv, NULL, fd); }
bool io_run_fg(const char **argv, const char *dir) { return io_complete(IO_FG, argv, dir, -1); }
bool io_run_bg(const char **argv) { return io_complete(IO_BG, argv, NULL, -1); }