summaryrefslogtreecommitdiff
path: root/common/extension.c
blob: a588ce892ece3b86c4dab4d2847d9a64b2a40c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* 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;
}