mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-01 21:02:27 +00:00
This patch introduces a facility which would allow to compile in callbacks for arbitrary commands passed over various communication protocols. Typically this will be used for testing, when various test commands are multiplexed over an existing protocol. The callbacks are associated with 16 bit command codes. On input the callback receives a buffer, containing the command's argument, the size of the command argument and the maximum size of the buffer. On output the callback stores processing result in the same buffer and updates the size to the actual amount of returned data. Callback descriptors are stored in a dedicated read only section which is scanned by extension_route_command() to find a callback associated with a certain command code. A console channel is also being introduced to allow controlling console output generated by extension commands handlers. BRANCH=none BUG=chrome-os-partner:47524 TEST=none yet Change-Id: I8ae16a78ca7d72176a5e7f74dd7a232078e7c06c Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/312586 Reviewed-by: Randall Spangler <rspangler@chromium.org>
37 lines
930 B
C
37 lines
930 B
C
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "byteorder.h"
|
|
#include "console.h"
|
|
#include "extension.h"
|
|
#include "link_defs.h"
|
|
|
|
#define CPRINTF(format, args...) cprintf(CC_EXTENSION, format, ## args)
|
|
|
|
void extension_route_command(uint16_t command_code,
|
|
void *buffer,
|
|
size_t in_size,
|
|
size_t *out_size)
|
|
{
|
|
struct extension_command *cmd_p;
|
|
struct extension_command *end_p;
|
|
|
|
cmd_p = (struct extension_command *)&__extension_cmds;
|
|
end_p = (struct extension_command *)&__extension_cmds_end;
|
|
|
|
while (cmd_p != end_p) {
|
|
if (cmd_p->command_code == command_code) {
|
|
cmd_p->handler(buffer, in_size, out_size);
|
|
return;
|
|
}
|
|
cmd_p++;
|
|
}
|
|
|
|
CPRINTF("%s: handler %d not found\n", __func__, command_code);
|
|
|
|
/* This covers the case of the handler not found. */
|
|
*out_size = 0;
|
|
}
|