Exemplo n.º 1
0
Arquivo: old.c Projeto: TurpIF/pi-nfc
phStatus_t initLayers()
{
  /* Initialize the Reader BAL (Bus Abstraction Layer) component */
  PH_CHECK_SUCCESS_FCT(status, phbalReg_R_Pi_spi_Init(&bal, sizeof(phbalReg_R_Pi_spi_DataParams_t)));
  PH_CHECK_SUCCESS_FCT(status, phbalReg_OpenPort((void *)&bal));

  /* we have a board with PN512,
   * but on the software point of view,
   * it's compatible to the RC523 */
  PH_CHECK_SUCCESS_FCT(status, phhalHw_Rc523_Init(&hal,
      sizeof(phhalHw_Rc523_DataParams_t),
      (void *)&bal,
      0,
      bHalBufferReader,
      sizeof(bHalBufferReader),
      bHalBufferReader,
      sizeof(bHalBufferReader)));

  /* Set the HAL configuration to SPI */
  PH_CHECK_SUCCESS_FCT(status, phhalHw_SetConfig(&hal, PHHAL_HW_CONFIG_BAL_CONNECTION,
      PHHAL_HW_BAL_CONNECTION_SPI));

  PH_CHECK_SUCCESS_FCT(status, phpalI14443p3a_Sw_Init(&palI14443p3a,
        sizeof(phpalI14443p3a_Sw_DataParams_t), &hal));

  PH_CHECK_SUCCESS_FCT(status, phpalI14443p4_Sw_Init(&palI14443p4,
        sizeof(phpalI14443p4_Sw_DataParams_t), &hal));

  PH_CHECK_SUCCESS_FCT(status, phpalMifare_Sw_Init(&palMifare,
        sizeof(phpalMifare_Sw_DataParams_t), &hal, &palI14443p4));

  PH_CHECK_SUCCESS_FCT(status, phalMfc_Sw_Init(&alMfc,
        sizeof(phalMfc_Sw_DataParams_t), &palMifare, NULL));

  return PH_ERR_SUCCESS;
}
Exemplo n.º 2
0
int Mifare_init(Mifare *self, PyObject *args, PyObject *kwds) {

    phStatus_t status;

    /* Initialize the Reader BAL (Bus Abstraction Layer) component */
    status = phbalReg_RpiSpi_Init(&self->data.balReader, sizeof(phbalReg_RpiSpi_DataParams_t));
    if (PH_ERR_SUCCESS != status)
    {
        PyErr_Format(InitError, "SPI Init failed: %04x", status);
        return -1;
    }

    status = phbalReg_OpenPort(&self->data.balReader);
    if (PH_ERR_SUCCESS != status)
    {
        PyErr_Format(InitError, "OpenPort failed: %04x", status);
        return -1;
    }

    /* we have a board with PN512,
    * but on the software point of view,
    * it's compatible to the RC523 */
    status = phhalHw_Rc523_Init(&self->data.hal,
        sizeof(phhalHw_Rc523_DataParams_t),
        &self->data.balReader,
        0,
        &self->data.bHalBufferReader[0],
        sizeof(self->data.bHalBufferReader),
        &self->data.bHalBufferReader[0],
        sizeof(self->data.bHalBufferReader));

    if (PH_ERR_SUCCESS != status)
    {
        PyErr_Format(InitError, "Rc523_Init failed: %04x", status);
        return -1;
    }

    /* Set the HAL configuration to SPI */
    status = phhalHw_SetConfig(&self->data.hal, PHHAL_HW_CONFIG_BAL_CONNECTION,
        PHHAL_HW_BAL_CONNECTION_SPI);
    if (PH_ERR_SUCCESS != status)
    {
        PyErr_Format(InitError, "SetConfig failed: %04x", status);
        return -1;
    }

    /* Initialize the 14443-3A PAL (Protocol Abstraction Layer) component */
    PH_CHECK_SUCCESS_FCT(status, phpalI14443p3a_Sw_Init(&self->data.I14443p3a,
        sizeof(phpalI14443p3a_Sw_DataParams_t), &self->data.hal));

    /* Initialize the 14443-4 PAL component */
    PH_CHECK_SUCCESS_FCT(status, phpalI14443p4_Sw_Init(&self->data.I14443p4,
        sizeof(phpalI14443p4_Sw_DataParams_t), &self->data.hal));

    /* Initialize the Mifare PAL component */
    PH_CHECK_SUCCESS_FCT(status, phpalMifare_Sw_Init(&self->data.palMifare,
        sizeof(phpalMifare_Sw_DataParams_t), &self->data.hal, &self->data.I14443p4));

    /* Initialize Ultralight(-C) AL component */
    PH_CHECK_SUCCESS_FCT(status, phalMful_Sw_Init(&self->data.alMful,
        sizeof(phalMful_Sw_DataParams_t), &self->data.palMifare, NULL, NULL, NULL));

    return 0;
}
Exemplo n.º 3
0
phStatus_t NfcRdLibInit(void)
{

    phStatus_t status;

    /*
     * Initialize the Reader BAL (Bus Abstraction Layer) component 
     */
    status = phbalReg_Stub_Init(&sBalReader, sizeof(phbalReg_Stub_DataParams_t));
    CHECK_SUCCESS(status);

    /*
     * Initialize the OSAL Events. 
     */
    status = phOsal_Event_Init();
    CHECK_STATUS(status);

    // Start interrupt thread
    Set_Interrupt();

    /*
     * Set HAL type in BAL 
     */
#ifdef NXPBUILD__PHHAL_HW_PN5180
    status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_PN5180);
#endif
#ifdef NXPBUILD__PHHAL_HW_RC523
    status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_RC523);
#endif
#ifdef NXPBUILD__PHHAL_HW_RC663
    status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_RC663);
#endif
    CHECK_STATUS(status);

    status = phbalReg_SetPort(&sBalReader, (uint8_t *) SPI_CONFIG);
    CHECK_STATUS(status);

    /*
     * Open BAL 
     */
    status = phbalReg_OpenPort(&sBalReader);
    CHECK_STATUS(status);

    /*
     * Initialize the Reader HAL (Hardware Abstraction Layer) component 
     */
    status = phhalHw_Nfc_IC_Init(&sHal_Nfc_Ic,
                                 sizeof(phhalHw_Nfc_Ic_DataParams_t),
                                 &sBalReader,
                                 0, bHalBufferTx, sizeof(bHalBufferTx), bHalBufferRx, sizeof(bHalBufferRx));
    CHECK_SUCCESS(status);

    /*
     * Set the parameter to use the SPI interface 
     */
    sHal_Nfc_Ic.sHal.bBalConnectionType = PHHAL_HW_BAL_CONNECTION_SPI;

    Configure_Device(&sHal_Nfc_Ic);

    /*
     * Set the generic pointer 
     */
    pHal = &sHal_Nfc_Ic.sHal;

    /*
     * Initializing specific objects for the communication with MIFARE (R) Classic cards. The MIFARE (R) Classic card
     * is compliant of ISO 14443-3 and ISO 14443-4 
     */

    /*
     * Initialize the I14443-A PAL layer 
     */
    status = phpalI14443p3a_Sw_Init(&spalI14443p3a, sizeof(phpalI14443p3a_Sw_DataParams_t), &sHal_Nfc_Ic.sHal);
    CHECK_STATUS(status);

    /*
     * Initialize the I14443-A PAL component 
     */
    status = phpalI14443p4a_Sw_Init(&spalI14443p4a, sizeof(phpalI14443p4a_Sw_DataParams_t), &sHal_Nfc_Ic.sHal);
    CHECK_STATUS(status);

    /*
     * Initialize the I14443-4 PAL component 
     */
    status = phpalI14443p4_Sw_Init(&spalI14443p4, sizeof(phpalI14443p4_Sw_DataParams_t), &sHal_Nfc_Ic.sHal);
    CHECK_STATUS(status);

    /*
     * Initialize the I14443-B PAL component 
     */
    status = phpalI14443p3b_Sw_Init(&spalI14443p3b, sizeof(phpalI14443p3b_Sw_DataParams_t), &sHal_Nfc_Ic.sHal);
    CHECK_STATUS(status);

    /*
     * Initialize the MIFARE PAL component 
     */
    status = phpalMifare_Sw_Init(&spalMifare, sizeof(phpalMifare_Sw_DataParams_t), &sHal_Nfc_Ic.sHal, NULL);
    CHECK_STATUS(status);

    /*
     * Initialize the discover component 
     */
    status = phacDiscLoop_Sw_Init(&sDiscLoop, sizeof(phacDiscLoop_Sw_DataParams_t), &sHal_Nfc_Ic.sHal);
    CHECK_SUCCESS(status);

    /*
     * Load profile for Discovery loop 
     */
    LoadProfile();

    status = phalMfc_Sw_Init(&salMfc, sizeof(phalMfc_Sw_DataParams_t), &spalMifare, NULL);
    CHECK_STATUS(status);

    /*
     * Read the version of the reader IC 
     */
#if defined NXPBUILD__PHHAL_HW_RC523
    status = phhalHw_Rc523_ReadRegister(&sHal_Nfc_Ic.sHal, PHHAL_HW_RC523_REG_VERSION, &bDataBuffer[0]);
    CHECK_SUCCESS(status);
#endif
#if defined NXPBUILD__PHHAL_HW_RC663
    status = phhalHw_Rc663_ReadRegister(&sHal_Nfc_Ic.sHal, PHHAL_HW_RC663_REG_VERSION, &bDataBuffer[0]);
    CHECK_SUCCESS(status);
#endif

    /*
     * Return Success 
     */
    return PH_ERR_SUCCESS;
}