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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* oFono - Open Source Telephony
* Copyright (C) 2014 Intel Corporation
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <sys/socket.h>
#include <glib.h>
#include <ofono.h>
#include <gdbus.h>
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/plugin.h>
#include <ofono/log.h>
#include <ofono/modem.h>
#include <ofono/emulator.h>
#include "hfp.h"
#define EMULATOR_FUZZ_INTERFACE "org.ofono.test.EmulatorFuzz"
#define EMULATOR_FUZZ_PATH "/test"
static void emulator_set_indicator(struct ofono_atom *atom, void *data)
{
struct ofono_emulator *em = __ofono_atom_get_data(atom);
ofono_bool_t active = GPOINTER_TO_INT(data);
ofono_emulator_set_hf_indicator_active(em,
HFP_HF_INDICATOR_ENHANCED_SAFETY, active);
}
static void modem_set_indicators(struct ofono_modem *modem, void *user)
{
__ofono_modem_foreach_registered_atom(modem,
OFONO_ATOM_TYPE_EMULATOR_HFP,
emulator_set_indicator,
user);
}
static DBusMessage *set_indicator_active(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
const char *indicator;
dbus_bool_t active;
DBG("");
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &indicator,
DBUS_TYPE_BOOLEAN, &active,
DBUS_TYPE_INVALID) == FALSE)
goto invalid;
DBG("%s,%d", indicator, active);
if (strcmp(indicator, "DistractedDrivingReduction"))
goto invalid;
__ofono_modem_foreach(modem_set_indicators, GINT_TO_POINTER(active));
return dbus_message_new_method_return(msg);
invalid:
return g_dbus_create_error(msg, "org.ofono.test.Error",
"Invalid arguments in method call");
}
static const GDBusMethodTable emulator_fuzz_methods[] = {
{ GDBUS_ASYNC_METHOD("SetIndicatorActive",
GDBUS_ARGS({ "indicator", "s" }, { "active", "b" }),
NULL, set_indicator_active) },
{ },
};
static int emulator_fuzz_init(void)
{
DBusConnection *conn = ofono_dbus_get_connection();
DBG("");
if (!g_dbus_register_interface(conn, EMULATOR_FUZZ_PATH,
EMULATOR_FUZZ_INTERFACE,
emulator_fuzz_methods, NULL,
NULL, NULL, NULL)) {
ofono_error("Register Profile interface failed: %s",
EMULATOR_FUZZ_PATH);
return -EIO;
}
return 0;
}
static void emulator_fuzz_exit(void)
{
DBusConnection *conn = ofono_dbus_get_connection();
DBG("");
g_dbus_unregister_interface(conn, EMULATOR_FUZZ_PATH,
EMULATOR_FUZZ_INTERFACE);
}
OFONO_PLUGIN_DEFINE(emulator_fuzz, "Emulator Fuzz",
VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
emulator_fuzz_init, emulator_fuzz_exit)
|