void root_ioctl(void * args){ sysfs_ioctl_t * p = args; const devfs_device_t * dev = (const devfs_device_t*)p->handle; //for IOCTLR, IOCTLW or IOCTLRW - check that p->ctl //is in a memory location that belongs to the process Issue #126 if( p->ctl ){ //a null value can have meaning for some drivers -- all IOCTL drivers should check for a null ctl value if( _IOCTL_IOCTLRW(p->request) ){ u32 size = _IOCTL_SIZE(p->request); if( task_validate_memory(p->ctl, size) < 0 ){ p->result = SYSFS_SET_RETURN(EPERM); return; } } } p->result = dev->driver.ioctl(&dev->handle, p->request, p->ctl); }
void link_cmd_ioctl(link_data_t * args){ int err; int size; size = _IOCTL_SIZE(args->op.ioctl.request); bootloader_attr_t attr; bootloader_writepage_t wattr; dstr("IOCTL REQ: "); dhex(args->op.ioctl.request); dstr("\n"); switch(args->op.ioctl.request){ case I_BOOTLOADER_ERASE: //the erase takes awhile -- so send the reply a little early link_protocol_slavewrite(phy_handle, &args->reply, sizeof(args->reply), NULL, NULL); args->op.cmd = 0; erase_flash(); is_erased = true; return; case I_BOOTLOADER_GETATTR: //write data to io_buf attr.version = BCDVERSION; _hwpl_core_getserialno(attr.serialno); err = link_protocol_slavewrite(phy_handle, &attr, size, NULL, NULL); if ( err == -1 ){ args->op.cmd = 0; args->reply.err = -1; } attr.startaddr = PROGRAM_START_ADDR; break; case I_BOOTLOADER_RESET: if( args->op.ioctl.arg == 0 ){ link_cmd_reset(args); } else { link_cmd_reset_bootloader(args); } break; case I_BOOTLOADER_WRITEPAGE: #ifdef __SECURE //decrypt incoming data #endif err = link_protocol_slaveread(phy_handle, &wattr, size, NULL, NULL); if( err < 0 ){ dstr("failed to read data\n"); break; } args->reply.err = flash_writepage(FLASH_PORT, (flash_writepage_t*)&wattr); if( args->reply.err < 0 ){ dstr("Failed to write flash\n"); } break; default: args->reply.err_number = EINVAL; args->reply.err = -1; break; } if ( args->reply.err < 0 ){ args->reply.err_number = errno; } }