Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27b30c61 authored by Henri Chataing's avatar Henri Chataing
Browse files

secure_element/aidl: Add error case for transmit()

Modify the semantics of transmit() to return a service
specific error with code CHANNEL_NOT_AVAILABLE if there
was an error in communicating with the secure element.

This can happen if the SE is put in low power mode when
no logical or basic channel is opened, e.g.

Bug: 270091254
Test: m VtsHalSecureElementTargetTest
Change-Id: I7df3ec6d9b6d5eeb2272971c44fc078a8558d2e6
parent 249640be
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -123,6 +123,9 @@ interface ISecureElement {
    /**
     * Transmits an APDU command (as per ISO/IEC 7816) to the SE.
     *
     * @throws ServiceSpecificException with code CHANNEL_NOT_AVAILABLE
     *  if there was an error in communicating with the secure element.
     *
     * @param data APDU command to be sent
     * @return response to the command
     */
+13 −4
Original line number Diff line number Diff line
@@ -136,18 +136,27 @@ class SecureElementAidl : public ::testing::TestWithParam<std::string> {
            apdu[0] |= (channel_number - 4) | 0x40;
        }

        EXPECT_OK(secure_element_->transmit(apdu, &response));
        // transmit() will return an empty response with the error
        // code CHANNEL_NOT_AVAILABLE when the SE cannot be
        // communicated with.
        auto status = secure_element_->transmit(apdu, &response);
        if (!status.isOk()) {
            return 0x6881;
        }

        // transmit() will return a response containing at least
        // the APDU response status otherwise.
        EXPECT_GE(response.size(), 2u);
        uint16_t status =
        uint16_t apdu_status =
                (response[response.size() - 2] << 8) | (response[response.size() - 1] << 0);

        // When the command is successful the response
        // must contain 256 bytes of data.
        if (status == 0x9000) {
        if (apdu_status == 0x9000) {
            EXPECT_EQ(response.size(), 258);
        }

        return status;
        return apdu_status;
    }

    std::shared_ptr<ISecureElement> secure_element_;