int main(void) { PaError result; EXPECT( ((result=Pa_Initialize()) == 0) ); printf("Test OUTPUT ---------------\n"); TestDevices( MODE_OUTPUT ); printf("Test INPUT ---------------\n"); TestDevices( MODE_INPUT ); error: Pa_Terminate(); printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed ); }
/************************************************************************** * * Function: ubsec_ioctl * *************************************************************************/ static int ubsec_ioctl(struct inode *inode,struct file *filp,unsigned int cmd, unsigned long arg) { long Retval=0; int status = 0; int deadlockctr = 0; unsigned short value; /* Simple round robin scheduling of device. We need to increment first since the keysetup command may block. */ TheBeginning: deadlockctr = 0; do { /* For diagnostic related stuff do not try any available devices */ /* Try the intended device or all devices as directed by the command */ if (cmd >= UBSEC_DEVICEDUMP || cmd == UBSEC_SELFTEST || cmd == UBSEC_FAILDEVICE) { break; } if(++deadlockctr == (NumDevices * 2)) { /* to be conservative... */ #ifdef DEBUG_FAILOVER PRINTK("dispatch found no more devices.\n"); #endif return 1; /* error: no more devices */ } if ((++SelectedDevice) == NumDevices) SelectedDevice=0; } while(GetDeviceStatus(DeviceInfoList[SelectedDevice])); #ifdef DEBUG_FAILOVER printk("\n"); PRINTK("dsptch-pre: SltdDev=%d,DevStati=%d %d\n", SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus); #endif switch(cmd) { #ifdef BCM_OEM_1 case BCM_OEM_1_IOCTL1: BCM_OEM1_IOCTL1_HANDLER(); break; case BCM_OEM_1_IOCTL2: BCM_OEM1_IOCTL2_HANDLER(); break; #endif /* BCM_OEM_1 */ case UBSEC_ENCRYPT_DECRYPT_FUNC: status = do_encrypt(DeviceInfoList[SelectedDevice].Context, (void *)arg, DeviceInfoList[SelectedDevice].Features); break; case UBSEC_KEY_SETUP_FUNC: status = ubsec_keysetup(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_MATH_FUNC: status = ubsec_math(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_RNG_FUNC: if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_RNG) status = ubsec_rng(DeviceInfoList[SelectedDevice].Context, (void *)arg); else status = UBSEC_STATUS_NO_DEVICE; break; case UBSEC_TLS_HMAC_FUNC: status = ubsec_tlsmac(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_SSL_MAC_FUNC: status = ubsec_sslmac(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_SSL_HASH_FUNC: status = ubsec_hash(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_SSL_DES_FUNC: status = ubsec_sslcipher(DeviceInfoList[SelectedDevice].Context, (void *)arg, DeviceInfoList[SelectedDevice].Features); break; case UBSEC_SSL_ARC4_FUNC: if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_ARC4) status = ubsec_sslarc4(DeviceInfoList[SelectedDevice].Context, (void *)arg); else status = UBSEC_STATUS_NO_DEVICE; break; case UBSEC_CHIPINFO_FUNC: status = obsolete_chipinfo(DeviceInfoList[SelectedDevice].Context, (void *)arg); break; case UBSEC_STATS_FUNC: { ubsec_stats_io_t IOInfo; int device_num; if (copy_from_user((void *) &IOInfo,(void *) arg, sizeof(ubsec_stats_io_t))) return -EFAULT; device_num = IOInfo.device_num; if ( (device_num >= NumDevices) || (device_num < 0) ) return -1; ubsec_GetStatistics(DeviceInfoList[device_num].Context, &IOInfo.dev_stats); if (copy_to_user((void *) arg, (void *) &IOInfo, sizeof(ubsec_stats_io_t))) return -EFAULT; } break; case UBSEC_EXTCHIPINFO_FUNC: if (copy_from_user((void *)&ExtChipInfo, (void *)arg, sizeof(ubsec_chipinfo_io_t))) return -EFAULT; if (ExtChipInfo.Status !=sizeof(ubsec_chipinfo_io_t)) { UserCopySize = sizeof(ubsec_chipinfo_io_t); if (UserCopySize > ExtChipInfo.Status) UserCopySize = ExtChipInfo.Status; ExtChipInfo.Status = UBSEC_STATUS_NO_DEVICE; if (copy_to_user((void *)arg, (void *)&ExtChipInfo, UserCopySize)) return -EFAULT; return(-1); } else if ((ExtChipInfo.CardNum >= NumDevices) || (ExtChipInfo.CardNum < 0)) { ExtChipInfo.CardNum = NumDevices; ExtChipInfo.Status = UBSEC_STATUS_INVALID_PARAMETER; } else { status = ubsec_chipinfo(DeviceInfoList[ExtChipInfo.CardNum].Context, &ExtChipInfo); ExtChipInfo.NumDevices = NumDevices; ExtChipInfo.Features &= DeviceInfoList[ExtChipInfo.CardNum].Features; ExtChipInfo.Status = UBSEC_STATUS_SUCCESS; } if (copy_to_user((void *)arg, (void *)&ExtChipInfo, sizeof(ubsec_chipinfo_io_t))) return -EFAULT; if (ExtChipInfo.Status != UBSEC_STATUS_SUCCESS) return(-1); else return(0); break; case UBSEC_DEVICEDUMP: if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int))) return -EFAULT; Retval=DumpDeviceInfo((PInt)&PInt_Contents); if (Retval) return(-1); /* Error */ break; case UBSEC_FAILDEVICE: if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int))) return -EFAULT; Retval=FailDevices((PInt)&PInt_Contents); if (Retval) return(-1); /* Error */ break; case UBSEC_SELFTEST: #ifdef BCM_OEM_1 DISABLE_BCM_OEM1(); #endif /*BCM_OEM_1 */ if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int))) return -EFAULT; Retval=TestDevices((PInt)&PInt_Contents); #ifdef BCM_OEM_1 ENABLE_BCM_OEM1(); #endif /*BCM_OEM_1 */ if (Retval) return (Retval); /* Error */ case UBSEC_GETVERSION: if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int))) return -EFAULT; Retval=GetHardwareVersion((PInt)&PInt_Contents); /* For the moment one card */ Retval=Retval<<16; Retval+=Version; #ifdef LINUX_IA64 return Retval; #else return(-Retval); #endif break; case UBSEC_GETNUMCARDS: if (copy_to_user((void *)arg,&NumDevices,sizeof(int))) return -EFAULT; return NumDevices; case UBSEC_GET_FUNCTION_PTRS: { ubsec_Function_Ptrs_t fptrs; get_ubsec_Function_Ptrs(&fptrs); if (copy_to_user((void *) arg, (void *) &fptrs, sizeof(ubsec_Function_Ptrs_t))) return -EFAULT; } break; #ifdef DVT case UBSEC_RESERVED: if (copy_from_user((void *)&DVTparams, (void *)arg, sizeof(DVT_Params_t))) return -EFAULT; if ((DVTparams.CardNum >= NumDevices) || (DVTparams.CardNum < 0)) { {PRINTK("Invalid CardNum (%d), must be 0",DVTparams.CardNum);} if (NumDevices == 1) printk("\n"); else printk("-%d\n",NumDevices-1); return -1; } switch (DVTparams.Command) { case UBSEC_DVT_PAGESIZE: /* Wrapper command */ DVTparams.OutParameter = Page_Size; if (!DVTparams.InParameter) { DVTparams.OutParameter = Page_Size = PAGE_SIZE; DVTparams.Status = UBSEC_STATUS_SUCCESS; Retval = UBSEC_STATUS_SUCCESS; } else if ((DVTparams.InParameter > PAGE_SIZE) || (DVTparams.InParameter < 2)) { DVTparams.Status = UBSEC_STATUS_INVALID_PARAMETER; } else { if (!power_of_2(DVTparams.InParameter)) DVTparams.InParameter = next_smaller_power_of_2(DVTparams.InParameter); DVTparams.OutParameter = Page_Size; Page_Size = DVTparams.InParameter; DVTparams.Status = UBSEC_STATUS_SUCCESS; Retval = UBSEC_STATUS_SUCCESS; } break; default: /* Pass all other commands down to the SRL */ Retval=ubsec_dvt_handler((void *)DeviceInfoList[DVTparams.CardNum].Context,(void *)&DVTparams); }; if (copy_to_user((void *)arg, (void *)&DVTparams, sizeof(DVT_Params_t))) return -EFAULT; return(Retval); break; #endif /* DVT */ default: return -EINVAL; } #ifdef DEBUG_FAILOVER PRINTK("dsptch-pst: SltdDev=%d,DevStati=%d %d\n", SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus); if((status == ETIMEDOUT) || (status == -ETIMEDOUT)) { PRINTK("dispatch.c: TIMED OUT SelectedDevice=%d, DeviceStatus=%d\n", SelectedDevice, DeviceInfoList[SelectedDevice].DeviceStatus); } #endif switch(status) { case 0: break; case (ETIMEDOUT): status = -ETIMEDOUT; case (-ETIMEDOUT): DeviceInfoList[SelectedDevice].DeviceStatus = TestDevice(SelectedDevice); /* goto TheBeginning; */ return(status); break; default: /* goto TheBeginning; */ return(status); break; } return 0; }