Exemple #1
0
static PyObject *
ETContext_ctrl_reset(ETContextObject* self)
{
  DWORD dwRet,dwOut;
  dwRet = ETControl(&self->context,ET_RESET_DEVICE,NULL,0,NULL,0,&dwOut);
  DWRET_VALIDATE(dwRet,NULL);
  Py_RETURN_TRUE;
}
Exemple #2
0
static PyObject *
ETContext_ctrl_led(ETContextObject* self, PyObject *args)
{
    DWORD onoff=0,wink=0,dwRet;
    if (!PyArg_ParseTuple(args, "i|i", &onoff,&wink)) {
      return NULL;
    }
    if(wink>0){
        dwRet = ETControl(&self->context,ET_LED_WINK,&wink,sizeof(wink),NULL,NULL,NULL);
        DWRET_VALIDATE(dwRet,NULL);
    }else{
        if(onoff){
            dwRet = ETControl(&self->context,ET_LED_UP,NULL,0,NULL,0,NULL);
            DWRET_VALIDATE(dwRet,NULL);
        }else{
            dwRet = ETControl(&self->context,ET_LED_DOWN,NULL,0,NULL,0,NULL);
            DWRET_VALIDATE(dwRet,NULL);
        }
    }
    Py_RETURN_TRUE;
}
Exemple #3
0
static int et199_encrypt_control(void *encrypt, int cmd, void *para)
{
	ENCRYPT *encrypt_ins = (ENCRYPT *)encrypt;
	struct ET_CONTEXT*pContext = (struct ET_CONTEXT*)encrypt_ins->private_data;
	int dwRet = 0;
	dwRet = ETControl(&pContext[0], cmd, (unsigned char *)para, sizeof(para), NULL, 0, NULL);
	if(dwRet)
	{
		PostError("ETControl ",dwRet);
		return CONTROL_ERR;
	}
	return SUCCESS;
}
Exemple #4
0
static int et199_encrypt_get_serial_num(void *encrypt, unsigned char *serial_num)
{
	unsigned long count = 0;
	int dwRet = 0;
	ENCRYPT *encrypt_ins = encrypt;
	struct ET_CONTEXT *pContext = (struct ET_CONTEXT *)encrypt_ins->private_data;
	dwRet = ETControl(&pContext[0], ET_GET_SERIAL_NUMBER, NULL, 0, (unsigned char *)serial_num, WDD_HARDWARE_ID_LEN, &count);
	if(dwRet)
	{
		PostError("et199_encrypt_get_serial_num", dwRet);
		printf("dwtret = %x\n", dwRet);
		return GET_SERIAL_ERR;
	}
	return SUCCESS;
}
Exemple #5
0
static PyObject *
ETContext_ctrl_set(ETContextObject* self, PyObject *args)
{
    DWORD ctrlcode=0,dwRet,dwOut,len;
    BYTE  buffer[24]={0};
    PyObject *pyParam=NULL;
    if (!PyArg_ParseTuple(args, "i|O", &ctrlcode,&pyParam)) {
      return NULL;
    }
    Py_XINCREF(pyParam);
    switch(ctrlcode){
      case ET_SET_DEVICE_ATR:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("ATR should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>16 || len<1){
          INVALID_PARAMS("ATR length must between 1~16!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_DEVICE_ATR,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_DEVICE_TYPE:
        if(NULL == pyParam || !PyInt_Check(pyParam)){
          INVALID_PARAMS("Param should be an integer.",NULL);
        }
        dwRet = PyInt_AsUnsignedLongMask(pyParam);
        if(dwRet!=ET_DEVICE_TYPE_PKI && dwRet!=ET_DEVICE_TYPE_DONGLE && dwRet!=ET_DEVICE_TYPE_EMPTY){
          INVALID_PARAMS("Device type should be 1,2 or 4!",NULL);
        }
        buffer[0] = dwRet;
        dwRet = ETControl(&self->context,ET_SET_DEVICE_ATR,buffer,1,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_SHELL_KEY:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("Shell key should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>8 || len<1){
          INVALID_PARAMS("ATR length must between 1~8!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_SHELL_KEY,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_CUSTOMER_NAME:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("Customer name should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>250 || len<1){
          INVALID_PARAMS("ATR length must between 1~250!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_CUSTOMER_NAME,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      default:
        INVALID_PARAMS("param must between ET_SET_DEVICE_ATR - ET_SET_CUSTOMER_NAME!",NULL);
        break;
    }
    Py_XDECREF(pyParam);
    Py_RETURN_TRUE;
}
Exemple #6
0
static PyObject *
ETContext_ctrl_get(ETContextObject* self, PyObject *args)
{
    DWORD ctrlcode=0,dwRet;
    BYTE  bFileId[5]={0};
    WORD  wFileId=0;
    DWORD fileIdLen=0,i;
    BYTE  outBuffer[256]={0},*pTmp;
    DWORD bytesReturned=0;
    PET_MANUFACTURE_DATE pManuDate=NULL;
    PEFINFO pFileInfo=NULL;
    PyObject *pyRet=NULL;
    if (!PyArg_ParseTuple(args, "i|H", &ctrlcode,&wFileId)) {
      return NULL;
    }

    switch(ctrlcode){
        case ET_GET_DEVICE_TYPE:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_TYPE,NULL,0,outBuffer,1,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0] as ?
            pyRet = Py_BuildValue("i",outBuffer[0]);
            break;
        case ET_GET_SERIAL_NUMBER:
            dwRet = ETControl(&self->context,ET_GET_SERIAL_NUMBER,NULL,0,outBuffer,9,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-7] as String
            return Py_BuildValue("z#",outBuffer,8);
            break;
        case ET_GET_DEVICE_USABLE_SPACE:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_USABLE_SPACE,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-3] as DWORD
            pyRet = Py_BuildValue("i",*(DWORD*)outBuffer);
            break;
        case ET_GET_DEVICE_ATR:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_ATR,NULL,0,outBuffer,17,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-15] as String
            pyRet = Py_BuildValue("z#",outBuffer,16);
            break;
        case ET_GET_CUSTOMER_NAME:
            dwRet = ETControl(&self->context,ET_GET_CUSTOMER_NAME,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-3] as DWORD
            pyRet = Py_BuildValue("I",*(DWORD*)outBuffer);
            break;
        case ET_GET_MANUFACTURE_DATE:
            pManuDate=(PET_MANUFACTURE_DATE)outBuffer;
            dwRet = ETControl(&self->context,ET_GET_MANUFACTURE_DATE,NULL,0,outBuffer,sizeof(ET_MANUFACTURE_DATE),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return pManuDate as DateTime
            #if 1
            pyRet = Py_BuildValue("(iiiiii)",2000+pManuDate->byYear,
                                              pManuDate->byMonth,
                                              pManuDate->byDay,
                                              pManuDate->byHour,
                                              pManuDate->byMinute,
                                              pManuDate->bySecond);
            #else //PyDateTime_FromDateAndTime cause a segmentation fault... WHY??
            Py_XINCREF()
            pyRet = PyDateTime_FromDateAndTime(2000+pManuDate->byYear,
                                              pManuDate->byMonth,
                                              pManuDate->byDay,
                                              pManuDate->byHour,
                                              pManuDate->byMinute,
                                              pManuDate->bySecond,
                                              0);
            #endif
            break;
        case ET_GET_DF_AVAILABLE_SPACE:
            dwRet = ETControl(&self->context,ET_GET_DF_AVAILABLE_SPACE,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-1] as WORD
            pyRet = Py_BuildValue("I",*(DWORD*)outBuffer);
            break;
        case ET_GET_EF_INFO:
            pFileInfo=(PEFINFO)outBuffer;
            if(bFileId==0){
                INVALID_PARAMS("An valid File Id should provide!",NULL);
            }
            sprintf(bFileId,"%04x",wFileId);
            dwRet = ETControl(&self->context,ET_GET_EF_INFO,bFileId,4,outBuffer,sizeof(EFINFO),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return pFileInfo as Dict
            pyRet = Py_BuildValue("{sHsbsI}",
                                    "wFileID",pFileInfo->wFileID,
                                    "bFileType",pFileInfo->bFileType,
                                    "wFileSize",pFileInfo->wFileSize);
            break;
        case ET_GET_COS_VERSION:
            dwRet = ETControl(&self->context,ET_GET_COS_VERSION,NULL,0,outBuffer,sizeof(WORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-1] as WORD
            pyRet = Py_BuildValue("H",*(WORD*)outBuffer);
            break;
        default:
            INVALID_PARAMS("param must between ET_GET_DEVICE_TYPE - ET_GET_COS_VERSION!",NULL);
            break;
    }
    Py_XINCREF(pyRet);
    return pyRet;
}