38 Commits
Author SHA1 Message Date
Richard Acayan 0b4c7bffaf fastrpc: hexagonrpcd: hexagonfs: mapped: return NULL for empty dirs
The mapped_or_empty file implementation uses NULL to denote when an
empty directory should be in place of a non-existent file. Changing the
pointer to the output has no effect. Change the implementation data to a
NULL pointer so empty directories function properly.
2023-12-04 19:50:34 -05:00
Richard Acayan 00b5f80608 fastrpc: hexagonrpcd: hexagonfs: initialize is_assigned in from_dirent
The is_assigned attribute should only be true when it is assigned a
numeric ID, otherwise it will not be closed. The from_dirent operations
in the implementations of a file type do not use the calloc() function,
so the is_assigned attribute is uninitialized. Initialize it to zero so
the open file can be closed when requested.
2023-12-04 19:50:24 -05:00
Richard Acayan 9ea9bed77b fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs
The malloc(3p) manual page states that an implementation may choose to
return a non-NULL pointer when the size is zero. This function assumes
that there is an element in the array if the pointer is not NULL. When
the size is zero, skip the allocation and return NULL.
2023-12-04 19:50:11 -05:00
Richard Acayan 23585daf67 qmi: add generated substitute
The qmic utility is rarely packaged in mainstream distributions, making
it inconvenient to set up a working build environment. Add generated
source files to enable compilation without qmic installed.
2023-12-04 19:49:59 -05:00
Richard Acayan e0d6c2a7ac fastrpc: hexagonrpcd: hexagonfs: remove static root filesystem
The root filesystem is now dynamically constructed in rpcd_builder.c.
Remove this macro-generated filesystem as it is unused and generates a
warning.
2023-11-27 18:53:31 -05:00
Richard Acayan 329f1ae841 fastrpc: hexagonrpcd: apps_std: remove unused variables
These variables went unused since the input buffer lengths were switched
to the sizes parsed by iobuffer.c, instead of the sizes in the primary
input argument. This makes it unnecessary at times to unpack the primary
input buffer, although the variables were being kept around to document
calling conventions. Remove the variables since they add unnecessary
warnings.

The calling conventions can still be found in the Android implementation
of FastRPC.
2023-11-27 18:53:31 -05:00
Richard Acayan 2358946095 fastrpc: hexagonrpcd: apps_std: include correct headers
This interface implementation no longer opens files directly, but sends
requests to hexagonfs. Hence, fcntl.h and dirent.h are no longer needed.
Also, it uses 32-bit integers from stdint.h.
2023-11-27 18:53:31 -05:00
Richard Acayan 06ef0b17a4 fastrpc: README: remove note about source code directory structure
This has been completed a long time ago.
2023-11-27 18:53:31 -05:00
Richard Acayan d87d8ffc47 fastrpc: README: mention correct interface listings
The interfaces being created on the reverse tunnel are now dynamically
generated.
2023-11-27 18:53:31 -05:00
Richard Acayan 947f52d779 fastrpc: README: clarify REMOTE_SCALARS_MAKE
This macro is used to generate the 32-bit remote "scalars"/"sc"
argument. Correct the name and link to the definition.
2023-11-27 18:53:31 -05:00
Richard Acayan 4983830139 fastrpc: README: add more usage documentation
The data types for the ioctl wrapper are important, as it has variable
arguments. Document them.

Also mention terminology used in QAIC output to aid in understanding
this project in relation to existing FastRPC implementations.
2023-11-27 18:53:31 -05:00
Richard Acayan 5e04177155 fastrpc: README: document meson build system
The meson.build was added a while ago.
2023-11-27 18:52:44 -05:00
Richard Acayan ee439dd6cb fastrpc: change copyright line
There are multiple contributors already, and copyright assignment is not
an intended requirement for contributing.
2023-11-27 18:52:18 -05:00
Richard Acayan b686df88d7 fastrpc: hexagonrpcd: builder: default required directories to empty
The sensor configuration is not required and is normally used just to
generate the sensor registry, but the sensors do not appear unless the
directory is present. The ADSP_LIBRARY_PATH virtual environment variable
may be used when opening absolute paths as a firmware quirk, even if
nothing is read from it. To remove the requirement of empty directories
in the physical filesystem, use the new hexagonfs_mapped_or_empty_ops.
2023-11-27 18:28:06 -05:00
Richard Acayan ccaa9728d9 fastrpc: hexagonrpcd: hexagonfs: add optionally mapped directories
Some directories are not required for the normal operation of the sensor
firmware, such as the sensor configuration directory. Add support for
directories that are empty if they are not present in the physical
filesystem.
2023-11-27 17:21:03 -05:00
Richard Acayan f5e05d0e7d fastrpc: README: correct the sensors registry path
The sensors registry path is in /persist/sensors/registry/registry and
not /persist/sensors/registry. Correct this in the README.
2023-08-01 19:09:04 -04:00
Richard Acayan b6d1f60ae9 fastrpc: hexagonrpcd: document added options in help text
The -R option specifies the root of the files served to the remote
processor (before mapping them to the virtual filesystem). The -d option
specifies the DSP variant, used to select the subdirectory storing the
libraries for the remote processor.
2023-07-27 21:04:15 -04:00
Richard Acayan ac6b6d61d0 fastrpc: hexagonrpcd: print most help text at once
There are multiple printf statements for each line of the help text.
Each line can be concatenated to one string at compile-time without
impacting readability of the intended output, with the exception of the
first line, with special formatting. Join the rest of the help text into
one printf statement.
2023-07-27 21:00:45 -04:00
Richard Acayan 44d4a818aa fastrpc: README: document new paths 2023-07-27 21:00:37 -04:00
Richard Acayan 2b8875d185 fastrpc: hexagonrpcd: accept path information from command line
Accept the path to files for the remote processor and the subdirectory
with the DSP shared object files on the command line.
2023-07-25 19:05:33 -04:00
Richard Acayan 4fb42aaa79 fastrpc: hexagonrpcd: specify device root path as absolute
The directory that stores the files for the remote processor is
specified relative to /usr/share/qcom. This is arbitrary and confuses
the user into thinking that the path is relative to the current working
directory. Specify it as absolute.
2023-07-25 19:05:28 -04:00
Richard Acayan d791bb48a0 fastrpc: hexagonrpcd: rework virtual filesystem sources
The virtual filesystem maps to physical files and directories. Move the
location of these physical files and directories according to #1.
2023-07-05 21:59:58 -04:00
Richard Acayan 9d97f21f4a fastrpc: hexagonrpcd: localctl: use inbuf size instead of provided len
The output of the adsp_listener interface provides the size of each
buffer in addition to the length provided to the remote method in the
primary buffer. Use the size of the buffer, which always corresponds to
the size allocated to it, regardless of whether there are consistency
checks.
2023-07-03 19:34:21 -04:00
Richard Acayan 1874e7a109 fastrpc: hexagonrpcd: apps_std: use inbuf size instead of provided len
The output of the adsp_listener interface provides the size of each
buffer in addition to the length provided to the remote method in the
primary buffer. Use the size of the buffer, which always corresponds to
the size allocated to it, regardless of whether there are consistency
checks.
2023-07-03 19:30:08 -04:00
Richard Acayan aa1cfca7b4 fastrpc: hexagonrpcd: apps_std: make fseek primary input buffer constant
The input buffers are not modified by the implementation of this remote
method. Make the primary input buffer constant.
2023-06-30 21:42:40 -04:00
Richard Acayan 4e2d1d46c6 fastrpc: hexagonrpcd: apps_std: make seek table constant
This is a read-only lookup table and is not modified during runtime.
Make it constant.

Also remove excessive empty lines.
2023-06-30 21:42:40 -04:00
Richard Acayan 3becf15c7a fastrpc: hexagonrpcd: apps_std: move fread method primary parameters
The only named structs for parameters in the primary input and output
buffers are for the fread remote method. Move them to the the place
where they are used, consistent with the other remote method
implementations.
2023-06-30 21:42:40 -04:00
Richard Acayan 3bf791122f fastrpc: hexagonrpcd: hexagonfs: do not store file descriptor array
The file descriptor array maps file descriptors to their corresponding
file descriptions, and is in static storage. Since there is range
checking for file descriptors, there is still a benefit to having access
to the file descriptor array. Accept the array as a parameter.

In the future, this parameter can be removed in secondary functions if
needed.
2023-06-30 21:42:40 -04:00
Richard Acayan ea226ef7b9 fastrpc: hexagonrpcd: apps_std: open directories on initialization
The apps_std interface stores file descriptors in static variables,
opening them when needed, and configures HexagonFS with a hardcoded root
directory. Configure HexagonFS and open the file descriptors in
initialization instead.
2023-06-30 21:42:40 -04:00
Richard Acayan 77ff6338be fastrpc: hexagonrpcd: hexagonfs: receive root directory argument
The root directory should not be hardcoded by hexagonfs, but the user of
it. Receive the root directory entry as an argument to the function that
opens the root directory.
2023-06-30 21:42:40 -04:00
Richard Acayan 1e83c7316e fastrpc: hexagonrpcd: localctl: use interface list from context
Now that the context is being initialized, use the interface list stored
in it.
2023-06-30 21:42:40 -04:00
Richard Acayan 3af581489d fastprc: hexagonrpcd: dynamically initialize interfaces
Some interfaces need to be configured before they can function.
Dynamically initialize the interfaces so there can be code to configure
them.
2023-06-30 21:42:40 -04:00
Richard Acayan 36bff0f541 fastrpc: hexagonrpcd: localctl: add context initialization
This interface depends on static variables to function properly. Add
code to initialize a context with the required data.

Do not use the context yet because it is not always initialized.
2023-06-30 21:42:40 -04:00
Richard Acayan 0ed58012fa fastrpc: hexagonrpcd: listener: move interfaces to listener user
The reverse tunnel finds interfaces in a static variable. As a
consequence, the interfaces cannot be customized by the user of the
reverse tunnel. Move the interfaces to the user of the listener.
2023-06-30 21:42:40 -04:00
Richard Acayan cd8a751732 fastrpc: hexagonrpcd: listener: declare procedure array as pointer
As an variable-length array within a struct, the procedure array is not
included in the sizeof() macro and cannot be trivially copied. Declare
it as a pointer to an array of procedures so the local fastrpc interface
definitions have a predictable size.
2023-06-30 21:42:40 -04:00
Richard Acayan 9946564fe9 fastrpc: hexagonrpcd: add interface contexts
Some interfaces preserve their states between invocations in static
storage. This is not ideal, as interfaces cannot be initialized with
information from the user of the reverse tunnel. Add support for
interface-defined contexts.
2023-06-30 21:42:40 -04:00
Richard Acayan 4a5f23e5d9 fastrpc: hexgaonrpcd: hexagonfs: remove offset property
This property should only be defined for file operations that need it.
Remove it from the common hexagonfs_fd struct and expect each file
operations to add it in the data pointer if necessary.
2023-06-05 18:07:46 -04:00
Richard Acayan 7dfd7d778c fastrpc: hexagonrpcd: hexagonfs: mapped: set functions to static
These functions are only referenced in the same compilation unit to
define file operations. Set these functions to static so they don't get
exported directly for no reason.
2023-06-05 18:07:40 -04:00
32 changed files with 924 additions and 358 deletions

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ which lines were entered by the user.
- libqrtr
- meson or make
- protobuf-c
- qmic (https://github.com/andersson/qmic)
- qmic (optional for regenerating QMI, at https://github.com/andersson/qmic)
# Installation
+28 -21
View File
@@ -14,9 +14,11 @@ interface compiler or a free software alternative.
## Installation
There is currently no build system.
You can build and install this project using meson:
$ gcc -o libhexagonrpc.so -shared fastrpc.c context.c
~/sensh/fastrpc $ meson setup build
~/sensh/fastrpc $ ninja -C build
~/sensh/fastrpc # ninja -C build install
## Usage
@@ -24,19 +26,27 @@ Making already-defined method calls is relatively straightforward, depending on
the remote method that you're calling. You just need the function definition, an
open file descriptor, the handle, and the arguments for it.
uint32_t prev_ctx, prev_result, nested_outbufs_len;
uint32_t ctx, nested_handle, nested_sc, nested_inbufs_len;
uint32_t nested_inbufs_size;
const void *nested_outbufs;
void *nested_inbufs;
int fd;
ret = fastrpc2(&adsp_listener_next2_def, fd, ADSP_LISTENER_HANDLE,
prev_ctx,
prev_result,
nested_outbufs_len, nested_outbufs,
ctx,
nested_handle,
nested_sc,
nested_inbufs_len,
&ctx,
&nested_handle,
&nested_sc,
&nested_inbufs_len,
nested_inbufs_size, nested_inbufs);
All inputs are specified before all outputs. Words in the first input and output
buffers go in the form of `uint32_t` arguments. Each buffer is accepted as a
`uint32_t` length and a pointer.
All inputs are specified before all outputs. Words in the first (called "prim",
or primary in QAIC-generated code) input and output buffers go in the form of
`uint32_t` arguments. Each buffer is accepted as a `uint32_t` length and a
pointer.
### Creating function definitions
@@ -45,8 +55,9 @@ first write a function definition for it. A function definition is a struct with
information on its method ID and the arguments it accepts.
First, the method ID is taken from the first argument of the
`REMOTE_METHOD_MAKE()` macro or the second argument of the
`REMOTE_METHOD_MAKEX()` macro.
`REMOTE_SCALARS_MAKE()` macro or the second argument of the
`REMOTE_SCALARS_MAKEX()` macro
(defined [here](https://android.googlesource.com/platform/external/fastrpc/+/d6d6e3bba244e40e6043bd687f4cacf090a767b5/inc/remote.h#80)).
Example:
@@ -109,7 +120,7 @@ or:
The reverse tunnel calls the `adsp_listener_next2` remote method to receive
method calls for the Application Processor.
Interfaces are listed in the `fastrpc_listener_interfaces` variable.
Interfaces are initialized in the `start_reverse_tunnel` function, in hexagonrpcd/rpcd.c.
## HexagonFS
@@ -117,21 +128,17 @@ The reverse tunnel's `apps_std` interface serves files to the remote processor.
These files are searched for in:
Physical file/dir Android file/dir
/etc/qcom/sns_reg.conf /vendor/etc/sensors/sns_reg_config
/etc/qcom/sensors.d /vendor/etc/sensors/config
/var/lib/qcom/sensors /mnt/vendor/persist/sensors/registry
/usr/lib/qcom/adsp /vendor/dsp/adsp
/usr/lib/qcom/adsp/avs /vendor/etc/acdbdata
/usr/share/qcom/acdb /vendor/etc/acdbdata
/usr/share/qcom/dsp /vendor/dsp
/usr/share/qcom/sensors/config /vendor/etc/sensors/config
/usr/share/qcom/sensors/registry /mnt/vendor/persist/sensors/registry/registry
/usr/share/qcom/sensors/sns_reg.conf /vendor/etc/sensors/sns_reg_config
These files and directories should be populated with files from your device's
Android firmware.
# Future plans
This directory is a bit messy. It should be organized into different
subdirectories and have a build system. This should also be renamed to
HexagonRPC to avoid a name collision.
Reverse tunnels are separated by the process that opens the file descriptor and
cannot service requests from other processes that do not share the same file
descriptor. There should be some daemon that opens the device and allows clients
File diff suppressed because it is too large. Load diff
+31
View File
@@ -0,0 +1,31 @@
/*
* FastRPC operating system interface - context initialization
*
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
* Sensh is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef APPS_STD_H
#define APPS_STD_H
#include "hexagonfs.h"
#include "listener.h"
struct fastrpc_interface *fastrpc_apps_std_init(struct hexagonfs_dirent *root);
void fastrpc_apps_std_deinit(struct fastrpc_interface *iface);
#endif
+14 -119
View File
@@ -1,7 +1,7 @@
/*
* Virtual read-only filesystem for Hexagon processors
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -29,111 +29,6 @@
#include "hexagonfs.h"
#define HEXAGONFS_MAX_FD 256
#define DEFINE_VIRT_DIR(dirname, files...) \
(struct hexagonfs_dirent) { \
.name = dirname, \
.ops = &hexagonfs_virt_dir_ops, \
.u.dir = (struct hexagonfs_dirent *[]) { files }, \
}
#define DEFINE_MAPPED(dirname, path) \
(struct hexagonfs_dirent) { \
.name = dirname, \
.ops = &hexagonfs_mapped_ops, \
.u.phys = path, \
}
#define DEFINE_SYSFILE(dirname, path) \
(struct hexagonfs_dirent) { \
.name = dirname, \
.ops = &hexagonfs_mapped_sysfs_ops, \
.u.phys = path, \
}
static struct hexagonfs_dirent root_dir = DEFINE_VIRT_DIR("/",
&DEFINE_VIRT_DIR("mnt",
&DEFINE_VIRT_DIR("vendor",
&DEFINE_VIRT_DIR("persist",
&DEFINE_VIRT_DIR("sensors",
&DEFINE_VIRT_DIR("registry",
&DEFINE_MAPPED("registry",
"/var/lib/qcom/sensors"),
NULL,
),
NULL,
),
NULL,
),
NULL,
),
NULL,
),
&DEFINE_VIRT_DIR("persist",
&DEFINE_VIRT_DIR("sensors",
&DEFINE_VIRT_DIR("registry",
&DEFINE_MAPPED("registry",
"/var/lib/qcom/sensors"),
NULL,
),
NULL,
),
NULL,
),
&DEFINE_VIRT_DIR("sys",
&DEFINE_VIRT_DIR("devices",
&DEFINE_VIRT_DIR("soc0",
&DEFINE_SYSFILE("hw_platform",
"/sys/kernel/debug/qcom_socinfo/hardware_platform"),
&(struct hexagonfs_dirent) {
.name = "platform_subtype",
.ops = &hexagonfs_plat_subtype_name_ops,
.u.phys = "/sys/kernel/debug/qcom_socinfo/hardware_platform_subtype",
},
&DEFINE_SYSFILE("platform_subtype_id",
"/sys/kernel/debug/qcom_socinfo/hardware_platform_subtype"),
&DEFINE_SYSFILE("platform_version",
"/sys/kernel/debug/qcom_socinfo/platform_version"),
&DEFINE_SYSFILE("revision",
"/sys/devices/soc0/revision"),
&DEFINE_SYSFILE("soc_id",
"/sys/devices/soc0/soc_id"),
NULL,
),
NULL,
),
NULL,
),
&DEFINE_VIRT_DIR("usr",
&DEFINE_VIRT_DIR("lib",
&DEFINE_VIRT_DIR("qcom",
&DEFINE_MAPPED("adsp",
"/usr/lib/qcom/adsp/"),
NULL,
),
NULL,
),
NULL,
),
&DEFINE_VIRT_DIR("vendor",
&DEFINE_VIRT_DIR("etc",
&DEFINE_VIRT_DIR("sensors",
&DEFINE_MAPPED("config",
"/etc/qcom/sensors.d/"),
&DEFINE_MAPPED("sns_reg_config",
"/etc/qcom/sns_reg.conf"),
NULL,
),
NULL,
),
NULL,
),
NULL,
);
static struct hexagonfs_fd *fds[HEXAGONFS_MAX_FD];
static char *copy_segment_and_advance(const char *path,
bool *trailing_slash,
const char **next)
@@ -183,7 +78,8 @@ static struct hexagonfs_fd *pop_dir(struct hexagonfs_fd *dir,
return up;
}
static int allocate_file_number(struct hexagonfs_fd *fd)
static int allocate_file_number(struct hexagonfs_fd **fds,
struct hexagonfs_fd *fd)
{
size_t i;
@@ -212,7 +108,7 @@ static void destroy_file_descriptor(struct hexagonfs_fd *fd)
}
}
int hexagonfs_open_root()
int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root)
{
struct hexagonfs_fd *fd;
int ret;
@@ -221,16 +117,15 @@ int hexagonfs_open_root()
if (fd == NULL)
return -ENOMEM;
fd->off = 0;
fd->is_assigned = false;
fd->up = NULL;
fd->ops = root_dir.ops;
fd->ops = root->ops;
ret = root_dir.ops->from_dirent(root_dir.u.ptr, true, &fd->data);
ret = root->ops->from_dirent(root->u.ptr, true, &fd->data);
if (ret)
goto err;
ret = allocate_file_number(fd);
ret = allocate_file_number(fds, fd);
if (ret < 0)
goto err;
@@ -241,7 +136,7 @@ err:
return ret;
}
int hexagonfs_openat(int rootfd, int dirfd, const char *name)
int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name)
{
struct hexagonfs_fd *fd;
const char *curr = name;
@@ -281,7 +176,7 @@ int hexagonfs_openat(int rootfd, int dirfd, const char *name)
if (ret)
goto err;
ret = allocate_file_number(fd);
ret = allocate_file_number(fds, fd);
if (ret)
goto err;
@@ -293,7 +188,7 @@ err:
return ret;
}
int hexagonfs_close(int fileno)
int hexagonfs_close(struct hexagonfs_fd **fds, int fileno)
{
struct hexagonfs_fd *fd;
@@ -312,7 +207,7 @@ int hexagonfs_close(int fileno)
return 0;
}
int hexagonfs_lseek(int fileno, off_t off, int whence)
int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t off, int whence)
{
struct hexagonfs_fd *fd;
@@ -329,7 +224,7 @@ int hexagonfs_lseek(int fileno, off_t off, int whence)
return fd->ops->seek(fd, off, whence);
}
ssize_t hexagonfs_read(int fileno, size_t size, void *ptr)
ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr)
{
struct hexagonfs_fd *fd;
@@ -346,7 +241,7 @@ ssize_t hexagonfs_read(int fileno, size_t size, void *ptr)
return fd->ops->read(fd, size, ptr);
}
int hexagonfs_readdir(int fileno, size_t ent_size, char *ent)
int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t ent_size, char *ent)
{
struct hexagonfs_fd *fd;
@@ -363,7 +258,7 @@ int hexagonfs_readdir(int fileno, size_t ent_size, char *ent)
return fd->ops->readdir(fd, ent_size, ent);
}
int hexagonfs_fstat(int fileno, struct stat *stats)
int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats)
{
struct hexagonfs_fd *fd;
+11 -9
View File
@@ -1,7 +1,7 @@
/*
* Virtual read-only filesystem for Hexagon processors
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#define HEXAGONFS_MAX_FD 256
struct hexagonfs_fd;
struct hexagonfs_file_ops {
@@ -54,7 +56,6 @@ struct hexagonfs_dirent {
};
struct hexagonfs_fd {
off_t off;
bool is_assigned;
struct hexagonfs_fd *up;
void *data;
@@ -63,17 +64,18 @@ struct hexagonfs_fd {
};
extern struct hexagonfs_file_ops hexagonfs_mapped_ops;
extern struct hexagonfs_file_ops hexagonfs_mapped_or_empty_ops;
extern struct hexagonfs_file_ops hexagonfs_mapped_sysfs_ops;
extern struct hexagonfs_file_ops hexagonfs_plat_subtype_name_ops;
extern struct hexagonfs_file_ops hexagonfs_virt_dir_ops;
int hexagonfs_open_root();
int hexagonfs_openat(int rootfd, int dirfd, const char *name);
int hexagonfs_close(int fileno);
int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root);
int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name);
int hexagonfs_close(struct hexagonfs_fd **fds, int fileno);
int hexagonfs_fstat(int fileno, struct stat *stats);
int hexagonfs_lseek(int fileno, off_t pos, int whence);
int hexagonfs_readdir(int fileno, size_t size, char *name);
ssize_t hexagonfs_read(int fileno, size_t size, void *ptr);
int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats);
int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t pos, int whence);
int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t size, char *name);
ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr);
#endif
+97 -4
View File
@@ -1,7 +1,7 @@
/*
* HexagonFS mapped file/directory operations
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -110,7 +110,7 @@ static int mapped_openat(struct hexagonfs_fd *dir,
ctx->dir = NULL;
fd->off = 0;
fd->is_assigned = false;
fd->up = dir;
fd->ops = &hexagonfs_mapped_ops;
fd->data = ctx;
@@ -126,7 +126,7 @@ err:
return ret;
}
ssize_t mapped_read(struct hexagonfs_fd *fd, size_t size, void *out)
static ssize_t mapped_read(struct hexagonfs_fd *fd, size_t size, void *out)
{
struct mapped_ctx *ctx = fd->data;
ssize_t ret;
@@ -138,7 +138,7 @@ ssize_t mapped_read(struct hexagonfs_fd *fd, size_t size, void *out)
return ret;
}
int mapped_readdir(struct hexagonfs_fd *fd, size_t size, char *out)
static int mapped_readdir(struct hexagonfs_fd *fd, size_t size, char *out)
{
struct mapped_ctx *ctx = fd->data;
struct dirent *ent;
@@ -216,6 +216,89 @@ static int mapped_stat(struct hexagonfs_fd *fd, struct stat *stats)
return 0;
}
static void mapped_or_empty_close(void *fd_data)
{
if (fd_data)
mapped_close(fd_data);
}
static int mapped_or_empty_from_dirent(void *dirent_data, bool dir, void **fd_data)
{
int ret;
ret = mapped_from_dirent(dirent_data, dir, fd_data);
if (ret)
*fd_data = NULL;
return 0;
}
static int mapped_or_empty_openat(struct hexagonfs_fd *dir,
const char *segment,
bool expect_dir,
struct hexagonfs_fd **out)
{
if (dir->data)
return mapped_openat(dir, segment, expect_dir, out);
else
return -ENOENT;
}
static ssize_t mapped_or_empty_read(struct hexagonfs_fd *fd,
size_t size, void *out)
{
if (fd->data)
return mapped_read(fd, size, out);
return 0;
}
static int mapped_or_empty_readdir(struct hexagonfs_fd *fd,
size_t size, char *out)
{
if (fd->data) {
return mapped_readdir(fd, size, out);
} else {
out[0] = '\0';
return 0;
}
}
static int mapped_or_empty_seek(struct hexagonfs_fd *fd, off_t off, int whence)
{
if (fd->data)
return mapped_seek(fd, off, whence);
else
return 0;
}
static int mapped_or_empty_stat(struct hexagonfs_fd *fd, struct stat *stats)
{
if (fd->data) {
return mapped_stat(fd, stats);
} else {
stats->st_size = 0;
stats->st_dev = 0;
stats->st_rdev = 0;
stats->st_ino = 0;
stats->st_nlink = 0;
stats->st_mode = S_IFDIR
| S_IRUSR | S_IXUSR
| S_IRGRP | S_IXGRP
| S_IROTH | S_IXOTH;
stats->st_atim.tv_sec = 0;
stats->st_atim.tv_nsec = 0;
stats->st_ctim.tv_sec = 0;
stats->st_ctim.tv_nsec = 0;
stats->st_mtim.tv_sec = 0;
stats->st_mtim.tv_nsec = 0;
return 0;
}
}
/*
* This is the sysfs variant of the stat function.
*
@@ -249,6 +332,16 @@ struct hexagonfs_file_ops hexagonfs_mapped_ops = {
.stat = mapped_stat,
};
struct hexagonfs_file_ops hexagonfs_mapped_or_empty_ops = {
.close = mapped_or_empty_close,
.from_dirent = mapped_or_empty_from_dirent,
.openat = mapped_or_empty_openat,
.read = mapped_or_empty_read,
.readdir = mapped_or_empty_readdir,
.seek = mapped_or_empty_seek,
.stat = mapped_or_empty_stat,
};
struct hexagonfs_file_ops hexagonfs_mapped_sysfs_ops = {
.close = mapped_close,
.from_dirent = mapped_from_dirent,
@@ -1,7 +1,7 @@
/*
* HexagonFS operations for a missing sysfs file
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+3 -2
View File
@@ -1,7 +1,7 @@
/*
* HexagonFS virtual directory operations
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -20,6 +20,7 @@
*/
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -69,7 +70,7 @@ static int virt_dir_openat(struct hexagonfs_fd *dir,
if (fd == NULL)
return -ENOMEM;
fd->off = 0;
fd->is_assigned = false;
fd->up = dir;
fd->ops = ent->ops;
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* FastRPC interface list for building method definitions
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel registration interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel main interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* FastRPC operating system interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* Context Hub Runtime Environment interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* Remote processor control interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel - argument decoder
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel I/O buffer encoder/decoder API
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
+21 -8
View File
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -73,6 +73,14 @@ static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_
off_t off;
uint32_t *sizes;
/*
* POSIX allows malloc to return a non-NULL pointer to a zero-size area
* in memory. Since the code below assumes non-zero size if the pointer
* is non-NULL, exit early if we do not need to allocate anything.
*/
if (out_count == 0)
return NULL;
out_count = def->out_bufs + (def->out_nums && 1);
out = malloc(sizeof(struct fastrpc_io_buffer) * out_count);
if (out == NULL)
@@ -202,7 +210,9 @@ err_free_outbufs:
return ret;
}
static int invoke_requested_procedure(uint32_t handle,
static int invoke_requested_procedure(size_t n_ifaces,
struct fastrpc_interface **ifaces,
uint32_t handle,
uint32_t sc,
uint32_t *result,
const struct fastrpc_io_buffer *decoded,
@@ -221,19 +231,19 @@ static int invoke_requested_procedure(uint32_t handle,
return 1;
}
if (handle >= fastrpc_listener_n_interfaces) {
if (handle >= n_ifaces) {
fprintf(stderr, "Unsupported handle: %u\n", handle);
*result = AEE_EUNSUPPORTED;
return 1;
}
if (method >= fastrpc_listener_interfaces[handle]->n_procs) {
if (method >= ifaces[handle]->n_procs) {
fprintf(stderr, "Unsupported method: %u (%08x)\n", method, sc);
*result = AEE_EUNSUPPORTED;
return 1;
}
impl = &fastrpc_listener_interfaces[handle]->procs[method];
impl = &ifaces[handle]->procs[method];
if (impl->def == NULL || impl->impl == NULL) {
fprintf(stderr, "Unsupported method: %u (%08x)\n", method, sc);
@@ -266,12 +276,14 @@ static int invoke_requested_procedure(uint32_t handle,
return 1;
}
*result = impl->impl(decoded, *returned);
*result = impl->impl(ifaces[handle]->data, decoded, *returned);
return 0;
}
int run_fastrpc_listener(int fd)
int run_fastrpc_listener(int fd,
size_t n_ifaces,
struct fastrpc_interface **ifaces)
{
struct fastrpc_io_buffer *decoded = NULL,
*returned = NULL;
@@ -298,7 +310,8 @@ int run_fastrpc_listener(int fd)
if (returned != NULL)
iobuf_free(n_outbufs, returned);
ret = invoke_requested_procedure(handle, sc, &result,
ret = invoke_requested_procedure(n_ifaces, ifaces,
handle, sc, &result,
decoded, &returned);
if (ret)
break;
+8 -4
View File
@@ -1,7 +1,7 @@
/*
* FastRPC reverse tunnel - header file
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -30,14 +30,16 @@
struct fastrpc_function_impl {
const struct fastrpc_function_def_interp2 *def;
uint32_t (*impl)(const struct fastrpc_io_buffer *inbufs,
uint32_t (*impl)(void *data,
const struct fastrpc_io_buffer *inbufs,
struct fastrpc_io_buffer *outbufs);
};
struct fastrpc_interface {
const char *name;
void *data;
uint8_t n_procs;
struct fastrpc_function_impl procs[];
const struct fastrpc_function_impl *procs;
};
extern const struct fastrpc_interface localctl_interface;
@@ -47,6 +49,8 @@ extern const struct fastrpc_interface apps_std_interface;
extern const struct fastrpc_interface *fastrpc_listener_interfaces[];
extern size_t fastrpc_listener_n_interfaces;
int run_fastrpc_listener(int fd);
int run_fastrpc_listener(int fd,
size_t n_ifaces,
struct fastrpc_interface **ifaces);
#endif
+59 -10
View File
@@ -1,7 +1,7 @@
/*
* Application processor control interface
*
* Copyright (C) 2023 Richard Acayan
* Copyright (C) 2023 The Sensor Shell Contributors
*
* This file is part of sensh.
*
@@ -28,6 +28,12 @@
#include "interfaces/remotectl.def"
#include "iobuffer.h"
#include "listener.h"
#include "localctl.h"
struct remotectl_ctx {
size_t n_ifaces;
struct fastrpc_interface **ifaces;
};
struct remotectl_open_invoke {
uint32_t inlen;
@@ -49,20 +55,22 @@ struct remotectl_open_return {
*
* The -5 error was taken from Android code.
*/
static uint32_t localctl_open(const struct fastrpc_io_buffer *inbufs,
static uint32_t localctl_open(void *data,
const struct fastrpc_io_buffer *inbufs,
struct fastrpc_io_buffer *outbufs)
{
struct remotectl_ctx *ctx = data;
const struct remotectl_open_invoke *first_in = inbufs[0].p;
struct remotectl_open_return *first_out = outbufs[0].p;
size_t i;
if (((const char *) inbufs[1].p)[first_in->inlen - 1] != 0)
if (((const char *) inbufs[1].p)[inbufs[1].s - 1] != 0)
return AEE_EBADPARM;
memset(outbufs[1].p, 0, first_in->outlen);
for (i = 0; i < fastrpc_listener_n_interfaces; i++) {
if (!strcmp(fastrpc_listener_interfaces[i]->name,
for (i = 0; i < ctx->n_ifaces; i++) {
if (!strcmp(ctx->ifaces[i]->name,
inbufs[1].p)) {
first_out->handle = i;
first_out->error = 0;
@@ -84,7 +92,8 @@ static uint32_t localctl_open(const struct fastrpc_io_buffer *inbufs,
* using an interface. It does not need to do anything because interfaces are
* static.
*/
static uint32_t localctl_close(const struct fastrpc_io_buffer *inbufs,
static uint32_t localctl_close(void *data,
const struct fastrpc_io_buffer *inbufs,
struct fastrpc_io_buffer *outbufs)
{
uint32_t *dlerr_size = inbufs[0].p;
@@ -97,11 +106,51 @@ static uint32_t localctl_close(const struct fastrpc_io_buffer *inbufs,
return 0;
}
struct fastrpc_interface *fastrpc_localctl_init(size_t n_ifaces,
struct fastrpc_interface **ifaces)
{
struct fastrpc_interface *iface;
struct remotectl_ctx *ctx;
iface = malloc(sizeof(struct fastrpc_interface));
if (iface == NULL)
return NULL;
ctx = malloc(sizeof(struct remotectl_ctx));
if (ctx == NULL)
goto err;
memcpy(iface, &localctl_interface, sizeof(struct fastrpc_interface));
ctx->n_ifaces = n_ifaces;
ctx->ifaces = ifaces;
iface->data = ctx;
return iface;
err:
free(iface);
return NULL;
}
void fastrpc_localctl_deinit(struct fastrpc_interface *iface)
{
if (iface == NULL)
return;
free(iface->data);
free(iface);
}
static const struct fastrpc_function_impl localctl_procs[] = {
{ .def = &remotectl_open_def, .impl = localctl_open, },
{ .def = &remotectl_close_def, .impl = localctl_close, },
};
const struct fastrpc_interface localctl_interface = {
.name = "remotectl",
.n_procs = 2,
.procs = {
{ .def = &remotectl_open_def, .impl = localctl_open, },
{ .def = &remotectl_close_def, .impl = localctl_close, },
},
.procs = localctl_procs,
};
Loaded 20 of 32 files, more files were not shown because too many files have changed in this diff. Show more