samples/qmi/qmi_sample_client.c
Source file repositories/reference/linux-study-clean/samples/qmi/qmi_sample_client.c
File Facts
- System
- Linux kernel
- Corpus path
samples/qmi/qmi_sample_client.c- Extension
.c- Size
- 14565 bytes
- Lines
- 621
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/debugfs.hlinux/device.hlinux/platform_device.hlinux/qrtr.hlinux/net.hlinux/completion.hlinux/idr.hlinux/string.hnet/sock.hlinux/soc/qcom/qmi.h
Detected Declarations
struct test_name_type_v01struct test_ping_req_msg_v01struct test_ping_resp_msg_v01struct test_data_req_msg_v01struct test_data_resp_msg_v01struct qmi_samplefunction ping_writefunction ping_pong_cbfunction data_writefunction memcmpfunction qmi_sample_probefunction qmi_sample_removefunction qmi_sample_new_serverfunction qmi_sample_del_serverfunction qmi_sample_initfunction qmi_sample_exitmodule init qmi_sample_init
Annotated Snippet
static const struct file_operations ping_fops = {
.open = simple_open,
.write = ping_write,
};
static void ping_pong_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
struct qmi_txn *txn, const void *data)
{
const struct test_ping_resp_msg_v01 *resp = data;
if (!txn) {
pr_err("spurious ping response\n");
return;
}
if (resp->resp.result == QMI_RESULT_FAILURE_V01)
txn->result = -ENXIO;
else if (!resp->pong_valid || memcmp(resp->pong, "pong", 4))
txn->result = -EINVAL;
complete(&txn->completion);
}
/*
* data_write() - data debugfs file write handler
* @file: debugfs file context
* @user_buf: reference to the user data
* @count: number of bytes in @user_buf
* @ppos: offset in @file to write
*
* This function allows user space to send out a data QMI encoded message to
* the associated remote test service and will return with the result of the
* transaction. It serves as an example of how to have the QMI helpers decode a
* transaction response into a provided object automatically.
*
* Return: @count, or negative errno on failure.
*/
static ssize_t data_write(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos)
{
struct qmi_handle *qmi = file->private_data;
struct test_data_resp_msg_v01 *resp;
struct test_data_req_msg_v01 *req;
struct qmi_txn txn;
int ret;
req = kzalloc(sizeof(*req), GFP_KERNEL);
if (!req)
return -ENOMEM;
resp = kzalloc(sizeof(*resp), GFP_KERNEL);
if (!resp) {
kfree(req);
return -ENOMEM;
}
req->data_len = min_t(size_t, sizeof(req->data), count);
if (copy_from_user(req->data, user_buf, req->data_len)) {
ret = -EFAULT;
goto out;
}
ret = qmi_txn_init(qmi, &txn, test_data_resp_msg_v01_ei, resp);
if (ret < 0)
goto out;
ret = qmi_send_request(qmi, NULL, &txn,
TEST_DATA_REQ_MSG_ID_V01,
TEST_DATA_REQ_MAX_MSG_LEN_V01,
test_data_req_msg_v01_ei, req);
if (ret < 0) {
qmi_txn_cancel(&txn);
goto out;
}
ret = qmi_txn_wait(&txn, 5 * HZ);
if (ret < 0) {
goto out;
} else if (!resp->data_valid ||
resp->data_len != req->data_len ||
memcmp(resp->data, req->data, req->data_len)) {
pr_err("response data doesn't match expectation\n");
ret = -EINVAL;
goto out;
}
ret = count;
out:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/debugfs.h`, `linux/device.h`, `linux/platform_device.h`, `linux/qrtr.h`, `linux/net.h`, `linux/completion.h`.
- Detected declarations: `struct test_name_type_v01`, `struct test_ping_req_msg_v01`, `struct test_ping_resp_msg_v01`, `struct test_data_req_msg_v01`, `struct test_data_resp_msg_v01`, `struct qmi_sample`, `function ping_write`, `function ping_pong_cb`, `function data_write`, `function memcmp`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.