Esempio n. 1
0
phStatus_t phalT1T_Sw_RequestA  (
                                 phalT1T_Sw_DataParams_t * pDataParams,      /**< [In] */
                                 uint8_t * pAtqa                             /**< [Out] */
                                 )
{
    return phpalI14443p3a_RequestA( pDataParams->pPalI14443p3aDataParams , pAtqa );
}
Esempio n. 2
0
PyObject *Mifare_select(Mifare *self)
{
    uint8_t byteBufferSize = UID_BUFFER_SIZE;
    uint8_t byteBuffer[UID_BUFFER_SIZE];

    uint8_t pAtqa[2];
    phStatus_t status;

    uint8_t bSak;
    uint8_t bMoreCardsAvailable;

    /* reset the IC  */
    phhalHw_Rc523_Cmd_SoftReset(&self->data.hal);

    /* Reset the RF field */
    if ((status = phhalHw_FieldReset(&self->data.hal)) != PH_ERR_SUCCESS) {
        return PyErr_Format(SelectError, "FieldReset command failed: %04x", status);
    }

    /* Apply the type A protocol settings
    * and activate the RF field. */
    if ((status = phhalHw_ApplyProtocolSettings(&self->data.hal, PHHAL_HW_CARDTYPE_ISO14443A)) != PH_ERR_SUCCESS) {
        return PyErr_Format(SelectError, "ApplyProtocolSettings command failed: %04x", status);
    }

    /* Empty the pAtqa */
    memset(pAtqa, '\0', 2);

    if ((status = phpalI14443p3a_RequestA(&self->data.I14443p3a, pAtqa)) != PH_ERR_SUCCESS) {
        return PyErr_Format(SelectError, "RequestA command failed: %04x", status);
    }

    /* Reset the RF field */
    if ((status = phhalHw_FieldReset(&self->data.hal)) != PH_ERR_SUCCESS) {
        return PyErr_Format(SelectError, "FieldReset command failed: %04x", status);
    }
    /* Activate the communication layer part 3 of the ISO 14443A standard. */
    if ( phpalI14443p3a_ActivateCard(&self->data.I14443p3a, NULL, 0x00, byteBuffer, &byteBufferSize, &bSak, &bMoreCardsAvailable) == PH_ERR_SUCCESS) {
        // Card is present, return it as a python object.
        uint8_t i;
        char asciiBuffer[UID_ASCII_BUFFER_SIZE];

        if (byteBufferSize + 1 > UID_ASCII_BUFFER_SIZE) {
            // Truncate if we got back too much data
            byteBufferSize = UID_ASCII_BUFFER_SIZE - 1;
        }

        for (i = 0; i < byteBufferSize; i++) {
            sprintf(&asciiBuffer[2 * i], "%02X", byteBuffer[i]);
        }

        return PyUnicode_FromString(asciiBuffer);
    }

    Py_RETURN_NONE;
}