int h_ch(struct cmd_desc *cmdd, struct atom *atoms) { int n_channels; n_channels = sis33dev_get_nr_subattrs(curr_index, "channels"); if (n_channels < 0) return n_channels; if (atoms == (struct atom *)VERBOSE_HELP) { printf("%s - Get/Set Channel\n" "%s [channel_nr]\n" "\tchannel_nr: 0-%d\n", cmdd->name, cmdd->name, n_channels - 1); return 1; } ++atoms; if (atoms->type == Terminator) { printf("%d\n", channel_nr); goto out; } if (atoms->type != Numeric || !WITHIN_RANGE(0, atoms->val, n_channels - 1)) return -TST_ERR_WRONG_ARG; channel_nr = atoms->val; out: return 1; }
static SkelUserReturn mtt_gs_tcb_ioctl(SkelDrvrClientContext *ccon, void *arg, int set) { struct udata *udata = get_udata_ccon(ccon); MttDrvrTaskBuf *taskbuf = arg; struct mtt_task *localtask = &udata->Tasks[taskbuf->Task - 1]; uint32_t mask; int i; /* sanity check */ if (!WITHIN_RANGE(1, taskbuf->Task, MttDrvrTASKS)) { pseterr(EINVAL); return SkelUserReturnFAILED; } cdcm_mutex_lock(&localtask->lock); if (set) { for (i = 0; i < MttDrvrTBFbits; i++) { mask = 1 << i; if (!(mask & taskbuf->Fields)) continue; __mtt_set_tcb(udata, taskbuf, mask); } } else { __mtt_get_tcb(udata, taskbuf); } cdcm_mutex_unlock(&localtask->lock); return SkelUserReturnOK; }
static SkelUserReturn mtt_send_event_ioctl(SkelDrvrClientContext *ccon, void *arg) { SkelDrvrModuleContext *mcon = get_mcon(ccon->ModuleNumber); MttDrvrEvent *event = arg; uint32_t cmd; if (!WITHIN_RANGE(0, event->Priority, 1)) { pseterr(EINVAL); return SkelUserReturnFAILED; } /* make sure thats the module supports prioritisation */ cmd = MttDrvrCommandSEND_EVENT; if (event->Priority && mtt_supports_prio(mcon)) cmd = MttDrvrCommandSEND_EVENT_LOW; mtt_cmd(mcon, cmd, event->Frame); return SkelUserReturnOK; }
int h_offset(struct cmd_desc *cmdd, struct atom *atoms) { int n_channels; int channel; int ret; n_channels = sis33dev_get_nr_subattrs(curr_index, "channels"); if (n_channels < 0) return n_channels; if (atoms == (struct atom *)VERBOSE_HELP) { printf("%s - Configure Input Offset\n" "%s channel_nr value\n" "\tchannel_nr: [0-%d]. -1 to select all channels\n" "\value: 16 bits (max. 0xffff.)\n", cmdd->name, cmdd->name, n_channels - 1); return 1; } ++atoms; if (atoms->type == Terminator) return show_chan_offset_all(); if (atoms->type != Numeric) return -TST_ERR_WRONG_ARG; if (!WITHIN_RANGE(-1, atoms->val, n_channels - 1)) return -TST_ERR_WRONG_ARG; channel = atoms->val; ++atoms; if (atoms->type != Numeric) return -TST_ERR_WRONG_ARG; ret = set_offset(atoms->val, channel); if (ret) return ret; printf("Updated:\n"); return show_chan_offset_all(); }
static SkelUserReturn mtt_gs_trval_ioctl(SkelDrvrClientContext *ccon, void *arg, int set) { struct udata *udata = get_udata_ccon(ccon); MttDrvrMap *map = udata->iomap; MttDrvrTaskRegBuf *trbuf = arg; int tasknum = trbuf->Task; unsigned long *mttmem = map->LocalMem[tasknum - 1]; int i; /* sanity check */ if (!WITHIN_RANGE(1, tasknum, MttDrvrTASKS)) { pseterr(EINVAL); return SkelUserReturnFAILED; } if (set) { int regmask; for (i = 0; i < MttDrvrLRAM_SIZE; i++) { regmask = 1 << i; if (!(regmask & trbuf->RegMask)) continue; cdcm_mutex_lock(&udata->lock); cdcm_iowrite32be(trbuf->RegVals[i], &mttmem[i]); cdcm_mutex_unlock(&udata->lock); return OK; } pseterr(EINVAL); return SkelUserReturnFAILED; } cdcm_mutex_lock(&udata->lock); for (i = 0; i < MttDrvrLRAM_SIZE; i++) trbuf->RegVals[i] = cdcm_ioread32be(&mttmem[i]); cdcm_mutex_unlock(&udata->lock); trbuf->RegMask = 0xffffffff; return OK; }
/** * @brief Lynx-like driver installation routine. * * @param drvr_fn -- driver path (.ko object) * @param type -- @ref BLOCKDRIVER or @ref CHARDRIVER\n * Special case is possible, where user can pass driver option * address (casted to @e int) in a string representation. * It will be passed to the init_module() system call as an * option to the driver installation (3-rd parameter) instead * of a standart one - which is a driver name. * * Will install the driver in the system. Supposed to be called @b ONLY once * during installation procedure. * @b NOTE If this routine will be called more then once during installation - * then it will terminate installation programm * * @return driver ID (major number) - if successful * @return -1 - if not */ int dr_install(char *drvr_fn, int type) { char *drvr_nm = NULL; /* extracted driver name */ int rc = 0; /* return code */ char *node_nm = NULL; /* driver node name */ void *drvrfile = NULL; /* our .ko */ FILE *procfd = NULL; unsigned long len; char *options = NULL; /* driver option */ long int ret; char buff[32], *bufPtr; /* for string parsing */ int major_num = 0; int devn; /* major/minor device number */ char *hotplug = NULL; drvr_nm = extract_driver_name(drvr_fn); if (!drvr_nm) { fprintf(stderr, "Wrong [.ko] object file name\n"); return -1; } /* put .ko in the local buffer */ if (!(drvrfile = grab_file(drvr_fn, &len))) { fprintf(stderr, "Can't read '%s': %s\n", drvr_fn, strerror(errno)); rc = -1; goto dr_install_exit; } /* check for special case. Will overwrite standart one! */ if (!WITHIN_RANGE(CHARDRIVER, type, BLOCKDRIVER)) /* this IS a special case. Setup user-defined extra options along with driver name */ asprintf(&options, "dname=%s %s", drvr_nm, (char*)type); else { asprintf(&options, "dname=%s", drvr_nm); } disable_kernel_hotplug(&hotplug); /* move mdev out-of-the-way */ /* insert module in the kernel */ if ( (ret = init_module(drvrfile, len, options)) != 0 ) { fprintf(stderr, "Error inserting '%s' module: %li %s\n", drvr_fn, ret, moderror(errno)); rc = -1; goto dr_install_exit; } /* check if he made it */ if ( (procfd = fopen("/proc/devices", "r")) == NULL ) { mperr("Can't open /proc/devices"); rc = -1; goto dr_install_exit; } /* search for the device driver entry */ bufPtr = buff; while (fgets(buff, sizeof(buff), procfd)) if (strstr(buff, drvr_nm)) { /* bingo! */ major_num = atoi(strsep(&bufPtr, " ")); break; } /* check if we cool */ if (!major_num) { fprintf(stderr, "'%s' device NOT found in procfs.\n", drvr_nm); rc = -1; goto dr_install_exit; } else printf("\n'%s' device driver installed. Major number %d.\n", drvr_nm, major_num); /* create service entry point */ asprintf(&node_nm, "/dev/%s.0", drvr_nm); unlink(node_nm); /* if already exist delete it */ devn = makedev(major_num, 0); if (mknod(node_nm, S_IFCHR | 0666, devn)) { mperr("Can't create %s service node", node_nm); rc = -1; goto dr_install_exit; } /* driverID (major num) will be used by the cdv_install() */ rc = major_num; dr_install_exit: if (hotplug) { /* hotplug was disabled -- re-enable it back */ set_kernel_hotplug(hotplug); free(hotplug); } if (drvr_nm) free(drvr_nm); if (options) free(options); if (drvrfile) free(drvrfile); if (node_nm) free(node_nm); return rc; }
static void _scanCurrArg(char *currArg) { char *saveCurrArg = currArg; switch (currArg[0]) { case '-': case '/': currArg++; switch (currArg++[0]) { case 'F': g_opt.structFieldsSep = currArg; break; case 'f': g_opt.targetLang = TLT_FORTRAN; break; case '?': case 'h': printUsageAndExit(); break; case 'i': addIncPath(currArg, 0, 1); break; case 'I': _scanSize(currArg, &(g_opt.intSize)); break; case 'j': g_opt.signedChar = 1; break; case 'l': if (currArg[0] == '=') { currArg++; } sscanf(currArg, "%u", &(g_opt.outLineLen)); if (!WITHIN_RANGE(g_opt.outLineLen, 30, MAX_OUT_LINE_LEN)) { reportError(ERR_LINE_LEN_OUT_OF_RANGE, g_opt.outLineLen); g_opt.outLineLen = 0; } break; case 'a': switch (currArg++[0]) { case 'd': g_opt.asmAttachD = 1; break; case 0: g_opt.targetLang = TLT_ASM; break; default: reportError(ERR_INV_CMD_LINE_OPTION, saveCurrArg); break; } break; case 's': switch (currArg++[0]) { case '-': g_opt.prefixStructFields = 0; _scanCurrArg("-F"); break; case '+': g_opt.prefixStructFields = 1; break; case '0': g_opt.supressLevel = 0; break; case '1': g_opt.supressLevel = 1; break; case '2': g_opt.supressLevel = 2; break; case '3': g_opt.supressLevel = 3; break; default: g_opt.supressLevel = 0; break; } break; case '1': if (currArg[0] == '6') { _scanCurrArg("-P16"); _scanCurrArg("-I16"); } break; case '3': if (currArg[0] == '2') { _scanCurrArg("-P32"); _scanCurrArg("-I32"); } break; case 'p': g_opt.conflictPrefix = currArg; break; case 'P': if (currArg[0] == 'n') { _scanSize(currArg+1, &(g_opt.nearPtrSize)); } else if (currArg[0] == 'p' || currArg[0] == 'd') { _scanSize(currArg+1, &(g_opt.ptrSize)); } else if (currArg[0] == 'f') { _scanSize(currArg+1, &(g_opt.farPtrSize)); } else if (currArg[0] == 'h') { _scanSize(currArg+1, &(g_opt.hugePtrSize)); } else { SizeType temp = SIZE_MAX; _scanSize(currArg, &temp); if (temp == SIZE_16) { _scanCurrArg("-Pn16"); _scanCurrArg("-Pd16"); _scanCurrArg("-Pf32"); _scanCurrArg("-Ph32"); } else if (temp == SIZE_32) { _scanCurrArg("-Pn32"); _scanCurrArg("-Pd32"); _scanCurrArg("-Pf32"); _scanCurrArg("-Ph48"); } } break; #ifndef NDEBUG case 'd': g_opt.debug = 1; break; #endif default: reportError(ERR_INV_CMD_LINE_OPTION, saveCurrArg); } break; case '?': printUsageAndExit(); break; default: { char driveDir[_MAX_DRIVE+_MAX_DIR+10]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char name[_MAX_FNAME]; char ext[_MAX_EXT]; int len; _splitpath(currArg, drive, dir, name, ext); _makepath(driveDir, drive, dir, "", ""); len = strlen(driveDir); if (len > 0) if (driveDir[len-1] == '\\') { driveDir[len-1] = 0; } addSLListElem(g_opt.fileNameList, wicStrdup(currArg)); addIncPath(driveDir, 0, 0); // Add at the beginning } } }