14 #include <communicator.h>
16 #include <user_request.h>
18 #include "generated-code.h"
21 #define TYPE_FACTORY 0x00020000
22 #define MAKE_REQ_CMD(id) (TREQ_CUSTOM|TYPE_FACTORY|id)
23 #define GET_OEM_ID(cmd) (cmd&0x0000FFFF)
25 static void _emit_oem_response(struct dbus_request_info *dbus_info, int oem_id, const void *data, unsigned int data_len)
27 if (!dbus_info || !oem_id || !data || !data_len) {
28 dbg("Invalid Data! dbus_info=%p, oem_id=0x%x, data=%p, data_len=%d", dbus_info, oem_id, data, data_len);
32 if (dbus_info->interface_object) {
33 gchar *encoded_data = g_base64_encode((const guchar*)data, data_len);
34 if (dbus_info->invocation) {
35 telephony_oem_complete_send_oem_data_with_response(dbus_info->interface_object, dbus_info->invocation, oem_id, encoded_data);
37 telephony_oem_emit_oem_data(dbus_info->interface_object, oem_id, encoded_data);
43 static void _emit_oem_notification(TelephonyOEM *oem, int oem_id, const void *data, unsigned int data_len)
45 gchar *encoded_data = NULL;
47 if (!oem || !oem_id || !data || !data_len) {
48 dbg("Invalid Data! oem=%p, oem_id=0x%x, data=%p, data_len=%d", oem, oem_id, data, data_len);
52 encoded_data = g_base64_encode((const guchar*)data, data_len);
53 telephony_oem_emit_oem_data(oem, oem_id, encoded_data);
58 send_oem_data(TelephonyOEM *oem,
59 GDBusMethodInvocation *invocation,
61 const gchar *arg_data,
63 gboolean remove_invocation)
65 struct custom_data *ctx = user_data;
66 UserRequest *ur = NULL;
69 guchar *decoded_data = NULL;
72 if (!check_access_control (invocation, AC_MODEM, "w"))
75 ur = MAKE_UR(ctx, oem, invocation);
76 decoded_data = g_base64_decode(arg_data, &length);
78 tcore_user_request_set_data(ur, length, decoded_data);
81 tcore_user_request_set_command(ur, MAKE_REQ_CMD(arg_oem_id));
83 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
84 if (ret != TCORE_RETURN_SUCCESS) {
85 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
86 tcore_user_request_unref(ur);
90 if (remove_invocation) {
91 struct dbus_request_info *dbus_info = tcore_user_request_ref_user_info(ur);
93 dbus_info->invocation = NULL;
95 telephony_oem_complete_send_oem_data(oem, invocation, result);
101 on_send_oem_data (TelephonyOEM *oem,
102 GDBusMethodInvocation *invocation,
104 const gchar *arg_data,
107 return send_oem_data(oem, invocation, arg_oem_id, arg_data, user_data, TRUE);
111 on_send_oem_data_with_response (TelephonyOEM *oem,
112 GDBusMethodInvocation *invocation,
114 const gchar *arg_data,
117 return send_oem_data(oem, invocation, arg_oem_id, arg_data, user_data, FALSE);
120 gboolean dbus_plugin_setup_oem_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
124 oem = telephony_oem_skeleton_new();
125 telephony_object_skeleton_set_oem(object, oem);
129 dbg("oem = %p", oem);
131 g_signal_connect (oem,
132 "handle-send-oem-data",
133 G_CALLBACK (on_send_oem_data),
136 g_signal_connect (oem,
137 "handle-send-oem-data-with-response",
138 G_CALLBACK (on_send_oem_data_with_response),
144 gboolean dbus_plugin_oem_response(struct custom_data *ctx, UserRequest *ur, struct dbus_request_info *dbus_info, enum tcore_response_command command, unsigned int data_len, const void *data)
146 _emit_oem_response(dbus_info, GET_OEM_ID(command), data, data_len);
150 gboolean dbus_plugin_oem_notification(struct custom_data *ctx, CoreObject *source, TelephonyObjectSkeleton *object, enum tcore_notification_command command, unsigned int data_len, const void *data)
152 _emit_oem_notification(telephony_object_peek_oem(TELEPHONY_OBJECT(object)), GET_OEM_ID(command), data, data_len);