Esempio n. 1
0
/* See Functional Specifications Document */
void CNALResetNFCController(
         void* pPortingConfig,
         uint32_t nResetType )
{
   tNALComInstance* pComPort = static_PComGetInstance();
   int ret;

   PNALDebugTrace("*****************  Reseting NFC Controller *********************\n");

   if (pComPort->fd != -1)
   {
      ret = ioctl(pComPort->fd, OPEN_NFC_IOC_RESET, NULL);

      if (ret == 0)
      {
         pComPort->reset_pending = W_TRUE;
      }
      else
      {
         PNALDebugError("Unable to perform  OPEN_NFC_IOC_RESET");
      }
   }

   return;

}
Esempio n. 2
0
int ms_open_nfc_admin_cbrecv(tNALMsrComInstance  *dev, unsigned char *inbuf, int len)
{
	PNALDebugLog( " ms_open_nfc_admin_cbrecv() - start \n");

	int retval = 0;

	PNALDebugLog( "command code: 0x%02X\n", dev->curCmdCode);
	switch( dev->curCmdCode)
	{
		case NAL_CMD_GET_PARAMETER:
			retval = ms_admin_cbrecv_get_parameter( dev, inbuf, len);
			break;

		default:
			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_UNKNOWN_COMMAND;
			dev->nb_available_bytes = 2;

			PNALDebugError( "wrong command code \n");
			break;
	}

	PNALDebugLog( " ms_open_nfc_admin_cbrecv() - end \n");
	return retval;
}
Esempio n. 3
0
static int ms_chk_internal_error(unsigned char *inbuf, int len)
{
    if (len == 3 && inbuf[0]==0xAA && inbuf[2] == 0x00)
    {
        PNALDebugError("[ms_tag_emulation_cb]has ms_chk_internal_error\n");
        return 1;
    }
    else
    {
        return 0;
    }
}
Esempio n. 4
0
static int ms_admin_cbrecv_get_parameter(tNALMsrComInstance  *dev, unsigned char *inbuf, int len)
{
	int retval = 0;
	PNALDebugLog( "ms_admin_cbrecv_get_parameter() - start \n");

	unsigned char firmwaredecp[32];
	unsigned char firmwareinfo[47];
	int idx;

	PNALDebugLog( "current parameter code: 0x%02X\n", CUR_PARAM_CODE);
	switch(CUR_PARAM_CODE)
	{
		case NAL_PAR_FIRMWARE_INFO:
			memset( firmwaredecp, 0, sizeof(firmwaredecp));
			sprintf( (char*)firmwaredecp, "%02x.%02x.20%02d-%02d-%02d-%02d.%02d.%02d",
				inbuf[2], inbuf[3], inbuf[7], inbuf[5], inbuf[6], inbuf[8], inbuf[9], inbuf[10]);

			PNALDebugLog( "Mixed: %02x %02x %02d %02d %02d %02d %02d %02d \n", inbuf[2], inbuf[3], inbuf[7], inbuf[5], inbuf[2], inbuf[8], inbuf[9], inbuf[10]);
			PNALDebugLog( "Mixed Result: %02x.%02x.20%02d-%02d-%02d-%02d.%02d.%02d \n", inbuf[2], inbuf[3], inbuf[7], inbuf[5], inbuf[6], inbuf[8], inbuf[9], inbuf[10]);

			memcpy( firmwareinfo, CST_PARAM_FIRMWARE_INFO, 47);
			memcpy( firmwareinfo + 1, firmwaredecp, 32);

			PNALDebugLog( "firmware info: \n");
			for( idx = 0; idx < 47; idx++)
			{
				PNALDebugLog( "0x%02X ", firmwareinfo[idx]);
			}
			PNALDebugLog( "\n");

			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_OK;
			memcpy( dev->rx_buffer + 2, firmwareinfo, 47);
			dev->nb_available_bytes = 1 + 1 + 47;

			break;

		default:
			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_UNKNOWN_PARAM;
			dev->nb_available_bytes = 2;

			PNALDebugError( "unknown parameter\n");
			break;

	}

	PNALDebugLog( "ms_admin_cbrecv_get_parameter() - end \n");
	return retval;
}
Esempio n. 5
0
/* See Functional Specification Document */
tNALInstance * CNALPreCreate(void * pPortingConfig)
{
   tNALInstance * pNALInstance = static_PNALGetInstance();

	CNALMemoryFill(pNALInstance, 0, sizeof(* pNALInstance));

   if (socketpair(AF_UNIX, SOCK_STREAM, 0, pNALInstance->aWakeUpSockets))
   {
      PNALDebugError("CNALPreCreate : socketpair() failed %d", errno);

		return null;
   }

	return pNALInstance;
}
Esempio n. 6
0
/* See Functional Specifications Document */
uint32_t CNALComWriteBytes(
         tNALComInstance* pComPort,
         uint8_t* pBuffer,
         uint32_t nBufferLength )
{
   ssize_t nResult = 0;

   if(pComPort != null)
   {
      nResult = write(pComPort->fd, pBuffer, nBufferLength);

      if ((nResult < 0) && (errno != EAGAIN))
      {
         PNALDebugError("PComWriteBytes : unable to send some data %d", errno);
         nResult = 0;
      }
   }

   return nResult;
}
Esempio n. 7
0
/* See Functional Specifications Document */
uint32_t CNALTimerGetCurrentTime( tNALTimerInstance* pTimer )
{
   uint32_t nCurrentTime = 0;

   CNALDebugAssert(pTimer != NULL);

   if( pTimer != NULL )
   {
      struct timespec tv;

      CNALDebugAssert( pTimer->bIsInitialized != W_FALSE );

      if (clock_gettime(CLOCK_MONOTONIC, &tv) == 0)
      {
         nCurrentTime = tv.tv_sec * 1000 + tv.tv_nsec / 1000000;
      }
      else
      {
         PNALDebugError("CNALTimerGetCurrentTime : clock_gettime() failed %d", errno);
      }
   }

   return nCurrentTime;
}
/* See NFC HAL Binding header file */
static tNALVoidContext* static_NALBindingCreate(
         void* pPortingConfig,
         void* pCallbackContext,
         uint8_t* pReceptionBuffer,
         uint32_t nReceptionBufferLength,
         tNALBindingReadCompleted* pReadCallbackFunction,
         void* pCallbackParameter,
         uint32_t nAutoStandbyTimeout,
         uint32_t nStandbyTimeout,
         tNALBindingTimerHandler* pTimerHandlerFunction,
         tNALBindingAntropySourceHandler* pAntropySourceHandlerFunction)
{
   uint32_t nComType;
   tNALSimulatorInstance* pInstance = (tNALSimulatorInstance*)CNALMemoryAlloc(
      sizeof(tNALSimulatorInstance));

   CNALMemoryFill(pInstance, 0x00, sizeof(tNALSimulatorInstance));

   CNALSyncCreateCriticalSection(&pInstance->hCriticalSection);

   pInstance->pReceptionBuffer = pReceptionBuffer;
   pInstance->nReceptionBufferLength = nReceptionBufferLength;
   pInstance->pReadCallbackFunction = pReadCallbackFunction;
   pInstance->pReadCallbackParameter = pCallbackParameter;

   pInstance->pTimerHandlerFunction = pTimerHandlerFunction;

   pInstance->pPortingConfig = pPortingConfig;
   pInstance->pCallbackContext = pCallbackContext;

   pInstance->pConnectCallbackFunction = null;
   pInstance->pConnectCallbackParameter = null;

   pInstance->nReceptionCounter = 0;

   pInstance->bIsConnected = W_FALSE;

   if ((pInstance->pNALInstance = CNALPreCreate(pPortingConfig)) == null)
   {
      PNALDebugError("static_NALBindingCreate: CNALPreCreate failed");
      goto return_error;
   }

   if((pInstance->pComPort = CNALComCreate(pPortingConfig, &nComType)) == null)
   {
      PNALDebugError("static_NALBindingCreateFunction: Cannot create the com port");
      goto return_error;
   }

   if((pInstance->pTimer = CNALTimerCreate(pPortingConfig)) == null)
   {
      PNALDebugError("static_NALBindingCreate: Cannot create the timer");
      goto return_error;
   }

   if (CNALPostCreate(pInstance->pNALInstance, pInstance) == W_FALSE)
   {
      PNALDebugError("CNALPostCreate failed");
      goto return_error;
   }

   return (tNALVoidContext*)pInstance;

return_error:

   static_NALBindingDestroy((tNALVoidContext*)pInstance);

   return null;
}
/* See NFC HAL Binding header file */
static void static_NALBindingPoll(
         tNALVoidContext* pNALContext)
{
  tNALSimulatorInstance* pInstance = (tNALSimulatorInstance*)pNALContext;

  CNALSyncEnterCriticalSection(&pInstance->hCriticalSection);

   if(CNALTimerIsTimerElapsed( pInstance->pTimer ))
   {
      CNALSyncLeaveCriticalSection(&pInstance->hCriticalSection);
      pInstance->pTimerHandlerFunction( pInstance->pCallbackContext );
      CNALSyncEnterCriticalSection(&pInstance->hCriticalSection);
   }

   if(pInstance->bIsConnected != W_FALSE)
   {
      int32_t nResult;

      if(pInstance->pComPort->pNFCCConnection != null)
      {
         if(pInstance->pWriteCallbackFunction != null)
         {
            tNALBindingWriteCompleted * pWriteCallback;

            pWriteCallback = pInstance->pWriteCallbackFunction;
            pInstance->pWriteCallbackFunction = null;

            CNALSyncLeaveCriticalSection(&pInstance->hCriticalSection);

            pWriteCallback(
               pInstance->pCallbackContext,
               pInstance->pWriteCallbackParameter,
               pInstance->nReceptionCounter++);

            CNALSyncEnterCriticalSection(&pInstance->hCriticalSection);
         }


			nResult = CNALComReadBytes(pInstance->pComPort, pInstance->pReceptionBuffer, pInstance->nReceptionBufferLength);

#if 0

         /* No more DATA => Restart Overlapped Reception */
         nResult = CCClientReceiveData(
                  pInstance->pComPort->pNFCCConnection,
                  pInstance->pComPort->aRXBuffer, P_MAX_RX_BUFFER_SIZE,
                  &pInstance->pComPort->pRXData);

         if( nResult < 0 )
         {
            PNALDebugError("An error occured during the read operation on the communication port");
            CNALComDestroy(pInstance->pComPort);
         }
         else if( nResult > 0 )
         {
            if((uint32_t)nResult > pInstance->nReceptionBufferLength)
            {
               PNALDebugError("Message received from the communication port is too long");
               nResult = (int32_t)pInstance->nReceptionBufferLength;
            }
            CNALMemoryCopy(pInstance->pReceptionBuffer, pInstance->pComPort->pRXData, (uint32_t)nResult);

            CNALSyncLeaveCriticalSection(&pInstance->hCriticalSection);


				if (nResult > 0)
				{
					pInstance->pReadCallbackFunction(
						pInstance->pCallbackContext,
						pInstance->pReadCallbackParameter,
						(uint32_t)nResult,
						pInstance->nReceptionCounter++);

				}
            CNALSyncEnterCriticalSection(&pInstance->hCriticalSection);
         }
 #endif

			if( nResult > 0 )
			{
				CNALSyncLeaveCriticalSection(&pInstance->hCriticalSection);

				pInstance->pReadCallbackFunction(
									pInstance->pCallbackContext,
									pInstance->pReadCallbackParameter,
									(uint32_t)nResult,
									pInstance->nReceptionCounter++);


				CNALSyncEnterCriticalSection(&pInstance->hCriticalSection);
			}
		}
   }
   else
   {
      if(pInstance->pConnectCallbackFunction != null)
      {
         pInstance->pConnectCallbackFunction(
            pInstance->pCallbackContext, pInstance->pConnectCallbackParameter, 0);

         pInstance->pConnectCallbackFunction = null;
         pInstance->pConnectCallbackParameter = null;

         pInstance->bIsConnected = W_TRUE;
      }
   }

   CNALSyncLeaveCriticalSection(&pInstance->hCriticalSection);
}
Esempio n. 10
0
static int ms_open_nfc_admin_cmd_get_parameter(tNALMsrComInstance  *dev, unsigned char *outbuf, int len)
{
	int retval = 0;

	PNALDebugLog( "ms_open_nfc_admin_cmd_get_parameter() - start \n");

	int interfaceSendRet = 0;

	CUR_PARAM_CODE = outbuf[2];
	switch(CUR_PARAM_CODE)
	{
		case NAL_PAR_HARDWARE_INFO:
			PNALDebugLog( " get NAL_PAR_HARDWARE_INFO - start \n");

			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_OK;
			memcpy( dev->rx_buffer + 2, CST_PARAM_HARDWARE_INFO, 0xFB);
			dev->nb_available_bytes = 1 + 1 + 0xFB;

			PNALDebugLog( " get NAL_PAR_HARDWARE_INFO - end \n");
			break;

		case NAL_PAR_PERSISTENT_POLICY:
			PNALDebugLog( " get NAL_PAR_PERSISTENT_POLICY - start \n");

			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_OK;
			memcpy( dev->rx_buffer + 2, CST_PARAM_PERSISTENT_POLICY, 8);
			dev->nb_available_bytes = 1 + 1 + 8;

			PNALDebugLog( " get NAL_PAR_PERSISTENT_POLICY - end \n");
			break;

		case NAL_PAR_FIRMWARE_INFO:
			PNALDebugLog( " get NAL_PAR_FIRMWARE_INFO - start \n");

#if 0 //ALAN_TEST

			dev->ant_send_buffer[0] = 0x05;
			dev->ant_send_buffer[1] = 0x01;
			dev->ant_send_buffer[2] = 0x00;

			//if( ms_interfaceSend(dev, 3) != 0)
			interfaceSendRet = ms_interfaceSend(dev, 3);
			//{
			//	PNALDebugError( "interfaceSend failed!");
			//	return -ENOTCONN;
			//}
			dev->cbRecv = ms_open_nfc_admin_cbrecv;
			retval = interfaceSendRet;
#endif
			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_OK;
			memcpy( dev->rx_buffer + 2, CST_PARAM_FIRMWARE_INFO, 47);
			dev->nb_available_bytes = 2 + 47;

			PNALDebugLog( " get NAL_PAR_FIRMWARE_INFO - end \n");
			break;

		case NAL_PAR_PERSISTENT_MEMORY:
			PNALDebugLog( " get NAL_PAR_PERSISTENT_MEMORY - start \n");

			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_OK;
			memcpy( dev->rx_buffer + 2, CST_PARAM_PERSISTENT_MEMORY, 8);
			dev->nb_available_bytes = 1 + 1 + 8;
			retval = 0;

			PNALDebugLog( " get NAL_PAR_PERSISTENT_MEMORY - end \n");
			break;

		default:
			PNALDebugError( " get DEFAULT - start \n");
			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_UNKNOWN_PARAM;
			dev->nb_available_bytes = 2;

			PNALDebugError( " get DEFAULT - end \n");
			break;
	}

	PNALDebugLog( "ms_open_nfc_admin_cmd_get_parameter() - end \n");
	return retval;
}
Esempio n. 11
0
int ms_detection_polling_getinfo_callback(tNALMsrComInstance  *dev, unsigned char *inbuf, int len)
{
    unsigned char infoType;	
	PNALDebugLog("[ms_detection_polling_getinfo_callback]start, len = %d\n", len);

	if (len <= 0)
	{
        //PNALDebugLog("[ms_detection_polling_getinfo_callback]recvlen < 0");
		ms_detection_polling_req(dev);
		return 0;	
	}
	
    PNALDebugLog("[ms_detection_polling_getinfo_callback]inbuf:");
    PNALDebugLogBuffer(inbuf, len);
    
    //A3Rsp(1)[0x02] , Len(1)[n], SubFuncCode(1), ParamNum(1) [n1], ParaID(1)[0x03],ParamLen(1)[n1+1],ID(1), OriginalRsp(n1)
    //PS: ID format: DrvPL_Category_et | DrvPL_PLItem_et    
    if ((inbuf[4] != 0xA1) || (inbuf[5] <= 1)) 
    {
        PNALDebugLog("Queue data is empty, do detection.");
		ms_detection_polling_req(dev);
		return 0;
    }
	infoType = inbuf[6];
	PNALDebugError("SWP Reset Cnt= %d", dev->swp_reset_cnt);
	PNALDebugLog("Info Type= %x", infoType);
	switch(infoType)
	{
	    case DrvPL_PLItem_R_ISO43A:
			ms_A3_RFID_43A_Inventory_Callback(dev, inbuf+7, inbuf[5]-1);
			break;

	    case DrvPL_PLItem_R_ISO43B:
			ms_open_nfc_43b_inventory_cbrecv(dev, inbuf+7, inbuf[5]-1);
			break;			

		case DrvPL_PLItem_R_ISO693:
			ms_A3_RFID_693_Inventory_Callback(dev, inbuf+7, inbuf[5]-1); 
			break;

		case DrvPL_PLItem_R_Felica:
			ms_open_nfc_felica_Inventory_callback(dev, inbuf+7, inbuf[5]-1);
			break;

		case DrvPL_PLItem_R_Type1:
			ms_open_nfc_type1_detection_sens_new_callback(dev, inbuf+7, inbuf[5]-1);
			break;

	    case DrvPL_PLItem_PI_P2P_212:
			break;

		case DrvPL_PLItem_PI_P2P_424:
			ms_open_nfc_initiator_detection_212_424_callback(dev, inbuf+7, inbuf[5]-1);
			break;

		case DrvPL_PLItem_PT_P2P_106:
			break;

		case DrvPL_PLItem_PT_P2P_212:
			break;

		case DrvPL_PLItem_PT_P2P_424:
			dev->sendTargetSddEvt = W_FALSE;
	        dev->temp_target_buf_len = 0;
			ms_nfc_p2p_target_enable_callback(dev, inbuf+7, inbuf[5]-1);
			break;	

		case DrvPL_PLItem_C_ISO43A:
			PNALDebugLog("43A Card Mode Started.");
			Start_IRQ_Detect(dev);
			break;		

		case DrvPL_PLItem_C_ISO43B:
			PNALDebugLog("43B Card Mode Started.");
            Start_IRQ_Detect(dev);    
			break;	

		case DrvPL_PLItem_C_CONN:
			PNALDebugLog("EVT_CONNECTIVITION");
			Start_IRQ_Detect(dev); 
			break;

		case DrvPL_PLItem_C_TRAN:
			PNALDebugLog("EVT_TRANSACTION");
			Start_IRQ_Detect(dev); 
			break;			

		case DrvPL_PLItem_PIT_P2P_424:
			PNALDebugLog("P2P IT Mode Started.");
			if (inbuf[10] == DRVP2P_result_As_Initiator)
			{
                PNALDebugLog("P2P IT Mode Started: Initiator");
				ms_open_nfc_initiator_detection_212_424_callback(dev, inbuf+7, inbuf[5]-1);
			}
			else if (inbuf[10] == DRVP2P_result_As_Target)
			{
                PNALDebugLog("P2P IT Mode Started: Target");
				dev->sendTargetSddEvt = W_FALSE;
	        	dev->temp_target_buf_len = 0;
				ms_nfc_p2p_target_enable_callback(dev, inbuf+7, inbuf[5]-1);
			}
			else
			{
			    PNALDebugError("P2P IT Mode Report Error");
			}
			break;

		case DrvPL_PLItem_Reset:
			PNALDebugLog("Reader need to Reset");
			dev->swp_reset_cnt++;			
			I2C_Reset();
			ms_card_detection(dev);
			break;

		default:
			break;
	}
	PNALDebugLog("[ms_detection_polling_getinfo_callback]end");
	return 1;
}
Esempio n. 12
0
int ms_open_nfc_admin_disp(tNALMsrComInstance  *dev, unsigned char *outbuf, int len)
{
    int retval = 0;
	int res = 0;

	PNALDebugLog( "ms_open_nfc_admin_disp() - start \n");

    if (outbuf == NULL || len == 0)
    {
    	PNALDebugError( "recieve buffer: NULL \n");
		PNALDebugLog( "ms_open_nfc_admin_disp() - end \n");
        return -1;
    }
    PNALDebugLog( "[ms_open_nfc_admin_disp]dev->curCmdCode:0x%02X\n", dev->curCmdCode);
    switch( dev->curCmdCode)
    {
        case NAL_CMD_GET_PARAMETER:
            retval = ms_open_nfc_admin_cmd_get_parameter( dev, outbuf, len);
            break;

        case NAL_CMD_SET_PARAMETER:
			retval = ms_open_nfc_admin_cmd_set_parameter(dev, outbuf, len);
            break;

		case NAL_CMD_UPDATE_FIRMWARE:
			retval = ms_open_nfc_admin_cmd_update_firmware(dev, outbuf, len);
            break;

		case NAL_CMD_DETECTION:
			retval = ms_open_nfc_admin_cmd_detection(dev, outbuf, len);
            break;

		case NAL_CMD_PRODUCTION_TEST:
			retval = ms_open_nfc_admin_cmd_production_test(dev, outbuf, len);
            break;

		case NAL_CMD_SELF_TEST:
			retval = ms_open_nfc_admin_cmd_self_test(dev, outbuf, len);
            break;

		case NAL_CMD_MS_READER_TEST:
			retval = ms_open_nfc_admin_ms_reader_test(dev, outbuf, len);
            break;
        case NAL_EVT_STANDBY_MODE:

            PNALDebugLog( ">>>>>> Standby Mode <<<<<<");
             if (outbuf[2] == 0x01)
            {
                //CNALComDestroy(dev);
                ms_open_nfc_standby_mode(dev);
				
            }
            else
            {
                PNALDebugLog( "[Standby Mode]wake up, send detect cmd");
				if (dev->bStandbyMode == W_TRUE)
			    {
			        PNALDebugLog("bStandbyMode=W_TRUE\n");
			        dev->bStandbyMode = W_FALSE;
			        MS_PowerOn();
			        dev->card_detect_mask = dev->temp_card_detect_mask;
			        dev->reader_detect_mask = dev->temp_reader_detect_mask;
			        ms_card_detection(dev);  
			    }
				//res = Reset_Write_Queue(dev);
            }
			CNALWriteDataFinish(dev);
            break;
        default:
			dev->rx_buffer[0] = NAL_SERVICE_ADMIN;
			dev->rx_buffer[1] = NAL_RES_UNKNOWN_COMMAND;
			dev->nb_available_bytes = 2;
			PNALDebugLog( "wrong command code \n");
            break;
    }

	PNALDebugLog( "ms_open_nfc_admin_disp() - end \n");
    return retval;
}
Esempio n. 13
0
int ms_open_nfc_uicc_disp(tNALMsrComInstance  *dev, unsigned char *outbuf, int len)
{
    int retval = 0;
	
	int length = 0;
	PNALDebugLog( "ms_open_nfc_uicc_disp() - start \n");

    if (outbuf == NULL || len == 0)
    {
    	PNALDebugError( "recieve buffer: NULL \n");
		PNALDebugLog( "ms_open_nfc_uicc_disp() - end \n");
        return -1;
    }
    PNALDebugLog( "[ms_open_nfc_uicc_disp]dev->curCmdCode:0x%02X\n", dev->curCmdCode);
    switch( dev->curCmdCode)
    {
        case NAL_CMD_UICC_START_SWP:
			PNALDebugLog("[NAL_CMD_UICC_START_SWP]start..."); 		
#if 0			
			//A3Cmd(1)[0x4B], Len(1)[n],Body(n)
			dev->ant_send_buffer[idx++] = PL_CMD_CODE;
			dev->ant_send_buffer[idx++] = 0;	  //LEN
			
			//Cmd Body Format
			//SubFuncCode(1), ParamNum(1) [n1] , Param_1(n2) ,	¡K , Param_n1(n3)
			dev->ant_send_buffer[idx++] = DrvPL_FuncCode_GetInfo; //SubFuncCode.
			dev->ant_send_buffer[idx++] = 0x01; 	  //ParamNum.
			
			dev->ant_send_buffer[idx++] = DrvPL_ModeParam_GetInfo;
			dev->ant_send_buffer[idx++] = 2;
			dev->ant_send_buffer[idx++] = 0x03;
			dev->ant_send_buffer[idx++] = 0x00;  
			dev->ant_send_buffer[1] = idx - 2;	  //LEN
			length = ms_interfaceSend(dev, idx);		
			dev->cbRecv = (RecvCallBack *)ms_swp_start_callback;	
			PNALDebugLog("[NAL_CMD_UICC_START_SWP]end...");				
#else
			MS_PowerOn();
			PNALDebugLog( "%s SLEEP-1", __FUNCTION__);
			usleep( 500000);
			PNALDebugLog( "%s SLEEP-2", __FUNCTION__);
			usleep( 500000);
			PNALDebugLog( "%s SLEEP-3", __FUNCTION__);
			usleep( 500000);
			PNALDebugLog( "%s SLEEP-END", __FUNCTION__);

            ms_swp_write_reg(dev);
#endif
            PNALDebugLog("[NAL_CMD_UICC_START_SWP]end..."); 	
            break;

        default:
			dev->rx_buffer[0] = dev->curSvcCode;
			dev->rx_buffer[1] = NAL_RES_OK;

			dev->nb_available_bytes = 2;
			PNALDebugLog( "wrong command code \n");
            break;
    }

	PNALDebugLog( "ms_open_nfc_admin_disp() - end \n");
    return retval;
}
Esempio n. 14
0
void * PDriverReceiveThread(void * arg)
{
   tNALInstance   * pNALInstance = static_PNALGetInstance();
   tNALComInstance    * pComPort = static_PComGetInstance();
   tNALTimerInstance  * pTimer = static_PTimerGetInstance();

   fd_set             readfds, writefds;
   int               data_fd, ctrl_fd, max_fd;

   uint32_t nTimeoutMs;
   struct timeval   tv;
   int res;
   uint8_t buffer[256];


   data_fd = pComPort->fd;
   ctrl_fd = pNALInstance->aWakeUpSockets[1];

   if (data_fd > ctrl_fd)
   {
      max_fd = data_fd + 1;
   }
   else
   {
      max_fd = ctrl_fd + 1;
   }

   for (;;)
   {
		bool_t bCallPoll = W_FALSE;
      FD_ZERO(&readfds);
      FD_ZERO(&writefds);

      FD_SET(data_fd, &readfds);
      FD_SET(ctrl_fd, &readfds);

      if (pComPort->reset_pending)
      {
         FD_SET(data_fd, &writefds);
      }

      if (pTimer->nTimerValue != 0)
      {
         uint32_t nCurrentTime = CNALTimerGetCurrentTime(pTimer);

         if (pTimer->nTimerValue > nCurrentTime)
         {
            nTimeoutMs = pTimer->nTimerValue - nCurrentTime;

            tv.tv_sec = nTimeoutMs / 1000;
            tv.tv_usec = (nTimeoutMs - tv.tv_sec * 1000) * 1000;

            res = select(max_fd, &readfds, &writefds, NULL, &tv);
         }
         else
         {
            res = 0;
         }
      }
      else
      {
         res = select(max_fd, &readfds, &writefds, NULL, null);
      }

      if (res < 0)
      {
         if (errno != EINTR)
         {
            PNALDebugError("PDriverReceiveThread : select failed : errno %d\n", errno);
            pthread_exit((void *) -1);
         }
      }
      else if (res > 0)
      {
			if ((FD_ISSET(data_fd, &readfds)) || ((FD_ISSET(data_fd, &writefds))))
         {
            /* some data has been received */
				bCallPoll = W_TRUE;
         }
			else
			{
				/* process data received on the control socket */
				int ret, i;

				ret = recv(ctrl_fd, buffer, sizeof(buffer), 0);

            if (((ret < 0) && (errno != EINTR)) || (ret == 0))
            {
               /* something goes wrong with the control socket, this typically occurs when exitin the service */

               pthread_exit((void *) -1);
            }


				for (i=0; i<ret; i++)
				{
					switch (buffer[i])
					{
						case EVENT_QUIT :
							pthread_exit((void *) -1);
							break;

						case EVENT_KICK :
							bCallPoll= W_TRUE;
							break;
					}
				}
			}
      }
      else
      {
         /* select returned due to a timeout */
         CNALTimerSetExpired(pTimer);
			bCallPoll = W_TRUE;
      }

		if (bCallPoll == W_TRUE)
		{
			g_pNALBinding->pPollFunction(arg);
		}
   }
}
Esempio n. 15
0
/* See Functional Specifications Document */
tNALComInstance* CNALComCreate(
               void* pPortingConfig,
               uint32_t* pnType )
{
   tNALComInstance* pComPort = static_PComGetInstance();
	struct open_nfc_ioc_configure config;
	uint32_t addr;

   int idx = 0;
   int ret;

   /*
    * open the device
    */

   pComPort->fd = open("/dev/nfcc", O_RDWR | O_NONBLOCK);

   if (pComPort->fd == -1)
   {
      PNALDebugError("Unable to open the device");
      goto return_error;
   }

   /*
    * configure the driver
    */



	addr = inet_addr((char *) pPortingConfig);

   /* first 4 bytes contain the IPV4 address of the Connection center */

	config.buffer[idx++] = (addr) >> 24;
   config.buffer[idx++] = (addr) >> 16;
   config.buffer[idx++] = (addr) >> 8;
   config.buffer[idx++] = (addr);

   /* the rest of the buffer contains the service name to connect */

   idx += sprintf((char *) (&config.buffer[idx]), "cc:nfcc_i2c") + 1;

   config.length = idx;

   ret = ioctl(pComPort->fd, OPEN_NFC_IOC_CONFIGURE, &config);

   if (ret < 0)
   {
      PNALDebugError("Unable to perform  OPEN_NFC_IOC_CONFIGURE");
      goto return_error;
   }

   /*
    * Establish the connection with the Connection Center
    */

   ret = ioctl(pComPort->fd, OPEN_NFC_IOC_CONNECT, NULL);

   if (ret < 0)
   {
      PNALDebugError("Unable to perform  OPEN_NFC_IOC_CONNECT");
      goto return_error;
   }


   /*
    * All is fine
    */

   *pnType = P_COM_TYPE_NFCC_SHDLC_I2C;

   return pComPort;

return_error:


   if (pComPort->fd != -1)
   {
      close(pComPort->fd);
      pComPort->fd = -1;
   }

   *pnType = 0;

   return null;
}