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

Commit be9de1ab authored by Matthew Maurer's avatar Matthew Maurer Committed by Gerrit Code Review
Browse files

Merge "Add support for mocked RPMB"

parents 5642bd23 503ea0e2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ static enum dev_type parse_dev_type(const char* dev_type_name) {
        return MMC_RPMB;
    } else if (!strcmp(dev_type_name, "virt")) {
        return VIRT_RPMB;
    } else if (!strcmp(dev_type_name, "sock")) {
        return SOCK_RPMB;
    } else {
        return UNKNOWN_RPMB;
    }
+29 −6
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

#include <linux/major.h>
@@ -192,7 +194,7 @@ int rpmb_send(struct storage_msg* msg, const void* r, size_t req_len) {
            msg->result = STORAGE_ERR_GENERIC;
            goto err_response;
        }
    } else if (dev_type == VIRT_RPMB) {
    } else if ((dev_type == VIRT_RPMB) || (dev_type == SOCK_RPMB)) {
        size_t payload_size = req->reliable_write_size + req->write_size;
        rc = send_virt_rpmb_req(rpmb_fd, read_buf, req->read_size, req->payload, payload_size);
        if (rc < 0) {
@@ -234,12 +236,33 @@ int rpmb_open(const char* rpmb_devname, enum dev_type open_dev_type) {
    int rc;
    dev_type = open_dev_type;

    if (dev_type != SOCK_RPMB) {
        rc = open(rpmb_devname, O_RDWR, 0);
        if (rc < 0) {
            ALOGE("unable (%d) to open rpmb device '%s': %s\n", errno, rpmb_devname, strerror(errno));
            return rc;
        }
        rpmb_fd = rc;
    } else {
        struct sockaddr_un unaddr;
        struct sockaddr *addr = (struct sockaddr *)&unaddr;
        rc = socket(AF_UNIX, SOCK_STREAM, 0);
        if (rc < 0) {
            ALOGE("unable (%d) to create socket: %s\n", errno, strerror(errno));
            return rc;
        }
        rpmb_fd = rc;

        memset(&unaddr, 0, sizeof(unaddr));
        unaddr.sun_family = AF_UNIX;
        // TODO if it overflowed, bail rather than connecting?
        strncpy(unaddr.sun_path, rpmb_devname, sizeof(unaddr.sun_path)-1);
        rc = connect(rpmb_fd, addr, sizeof(unaddr));
        if (rc < 0) {
            ALOGE("unable (%d) to connect to rpmb socket '%s': %s\n", errno, rpmb_devname, strerror(errno));
            return rc;
        }
    }
    return 0;
}

+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#include <stdint.h>
#include <trusty/interface/storage.h>

enum dev_type { UNKNOWN_RPMB, MMC_RPMB, VIRT_RPMB };
enum dev_type { UNKNOWN_RPMB, MMC_RPMB, VIRT_RPMB, SOCK_RPMB };

int rpmb_open(const char* rpmb_devname, enum dev_type dev_type);
int rpmb_send(struct storage_msg* msg, const void* r, size_t req_len);
+33 −0
Original line number Diff line number Diff line
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at //
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_binary {
    name: "rpmb_dev",
    vendor: true,

    srcs: [
        "rpmb_dev.c",
    ],
    shared_libs: [
        "libc",
        "liblog",
        "libcrypto",
    ],
    cflags: [
        "-Wall",
        "-Werror",
    ],
    init_rc: [
        "rpmb_dev.rc",
    ],
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __RPMB_H__
#define __RPMB_H__

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

struct rpmb_key {
    uint8_t byte[32];
};

struct rpmb_state;

#define RPMB_BUF_SIZE 256

/* provides */
int rpmb_init(struct rpmb_state** statep,
              void* mmc_handle,
              const struct rpmb_key* key);
void rpmb_uninit(struct rpmb_state* statep);
int rpmb_read(struct rpmb_state* state,
              void* buf,
              uint16_t addr,
              uint16_t count);
/* count must be 1 or 2, addr must be aligned */
int rpmb_write(struct rpmb_state* state,
               const void* buf,
               uint16_t addr,
               uint16_t count,
               bool sync);

/* needs */
int rpmb_send(void* mmc_handle,
              void* reliable_write_buf,
              size_t reliable_write_size,
              void* write_buf,
              size_t write_buf_size,
              void* read_buf,
              size_t read_buf_size,
              bool sync);

#endif
Loading