~cyphermox/+junk/bluez-debug

« back to all changes in this revision

Viewing changes to sap/sap-dummy.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-07-04 13:28:49 UTC
  • mfrom: (1.1.38)
  • Revision ID: package-import@ubuntu.com-20120704132849-tmwu1x7p2vxcclt1
Tags: 4.101-0ubuntu1
* New upstream release
* debian/libbluetooth3.symbols:
  - Updated
* debian/patches/10-unregister_interface_on_exit.patch:
* debian/patches/11-explicitly_close.patch:
* debian/patches/python3.patch:
  - Applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <config.h>
27
27
#endif
28
28
 
29
 
#include <unistd.h>
30
 
#include <stdlib.h>
31
 
#include <stdint.h>
32
29
#include <glib.h>
33
30
#include <gdbus.h>
34
31
 
39
36
#define SAP_DUMMY_PATH "/org/bluez/test"
40
37
 
41
38
enum {
42
 
        SIM_DISCONNECTED= 0x00,
43
 
        SIM_CONNECTED   = 0x01,
44
 
        SIM_POWERED_OFF = 0x02,
45
 
        SIM_MISSING     = 0x03
 
39
        SIM_DISCONNECTED = 0x00,
 
40
        SIM_CONNECTED    = 0x01,
 
41
        SIM_POWERED_OFF  = 0x02,
 
42
        SIM_MISSING      = 0x03
46
43
};
47
44
 
48
45
static DBusConnection *connection = NULL;
49
46
 
50
47
static int sim_card_conn_status = SIM_DISCONNECTED;
51
 
static void *sap_data = NULL;  /* SAP server private data.*/
 
48
static void *sap_data = NULL; /* SAP server private data. */
52
49
static gboolean ongoing_call_status = FALSE;
53
50
static int max_msg_size_supported = 512;
54
51
 
60
57
                sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED,
61
58
                                                                maxmsgsize);
62
59
                return;
63
 
        } else if (max_msg_size_supported > maxmsgsize) {
 
60
        }
 
61
 
 
62
        if (max_msg_size_supported > maxmsgsize) {
64
63
                sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL,
65
64
                                                max_msg_size_supported);
66
65
                return;
67
 
        } else if (max_msg_size_supported < maxmsgsize) {
 
66
        }
 
67
 
 
68
        if (max_msg_size_supported < maxmsgsize) {
68
69
                sap_connect_rsp(sap_device,
69
70
                                SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED,
70
71
                                max_msg_size_supported);
71
72
                return;
72
 
        } else if (ongoing_call_status) {
 
73
        }
 
74
 
 
75
        if (ongoing_call_status) {
73
76
                sap_connect_rsp(sap_device, SAP_STATUS_OK_ONGOING_CALL,
74
77
                                                max_msg_size_supported);
75
78
                return;
76
 
        } else {
77
 
                sim_card_conn_status = SIM_CONNECTED;
78
 
                sap_data = sap_device;
79
 
 
80
 
                sap_connect_rsp(sap_device, SAP_STATUS_OK, maxmsgsize);
81
 
                sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
82
79
        }
 
80
 
 
81
        sim_card_conn_status = SIM_CONNECTED;
 
82
        sap_data = sap_device;
 
83
 
 
84
        sap_connect_rsp(sap_device, SAP_STATUS_OK, maxmsgsize);
 
85
        sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
83
86
}
84
87
 
85
88
void sap_disconnect_req(void *sap_device, uint8_t linkloss)
113
116
                        SAP_RESULT_ERROR_NOT_ACCESSIBLE, NULL, 0);
114
117
        else
115
118
                sap_transfer_apdu_rsp(sap_device, SAP_RESULT_OK,
116
 
                                                (uint8_t*)&apdu, sizeof(apdu));
 
119
                                                (uint8_t *)&apdu, sizeof(apdu));
117
120
}
118
121
 
119
122
void sap_transfer_atr_req(void *sap_device)
133
136
                                                                NULL, 0);
134
137
        else
135
138
                sap_transfer_atr_rsp(sap_device, SAP_RESULT_OK,
136
 
                                                (uint8_t*)&atr, sizeof(atr));
 
139
                                                (uint8_t *)&atr, sizeof(atr));
137
140
}
138
141
 
139
142
void sap_power_sim_off_req(void *sap_device)
227
230
        if (ongoing_call_status && !ongoing) {
228
231
                /* An ongoing call has finished. Continue connection.*/
229
232
                sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_RESET);
230
 
                ongoing_call_status = ongoing;
 
233
                ongoing_call_status = FALSE;
231
234
        } else if (!ongoing_call_status && ongoing) {
232
235
                /* An ongoing call has started.*/
233
 
                ongoing_call_status = ongoing;
 
236
                ongoing_call_status = TRUE;
234
237
        }
235
238
 
236
239
        DBG("OngoingCall status set to %d", ongoing_call_status);
315
318
        return dbus_message_new_method_return(msg);
316
319
}
317
320
 
318
 
static GDBusMethodTable dummy_methods[] = {
319
 
        { "OngoingCall", "b", "", ongoing_call},
320
 
        { "MaxMessageSize", "u", "", max_msg_size},
321
 
        { "DisconnectImmediate", "", "", disconnect_immediate},
322
 
        { "CardStatus", "u", "", card_status},
 
321
static const GDBusMethodTable dummy_methods[] = {
 
322
        { GDBUS_METHOD("OngoingCall",
 
323
                                GDBUS_ARGS({ "ongoing", "b" }), NULL,
 
324
                                ongoing_call) },
 
325
        { GDBUS_METHOD("MaxMessageSize",
 
326
                                GDBUS_ARGS({ "size", "u" }), NULL,
 
327
                                max_msg_size) },
 
328
        { GDBUS_METHOD("DisconnectImmediate", NULL, NULL,
 
329
                                disconnect_immediate) },
 
330
        { GDBUS_METHOD("CardStatus",
 
331
                                GDBUS_ARGS({ "status", "" }), NULL,
 
332
                                card_status) },
323
333
        { }
324
334
};
325
335
 
332
342
                                NULL, NULL) == FALSE) {
333
343
                error("sap-dummy interface %s init failed on path %s",
334
344
                                        SAP_DUMMY_IFACE, SAP_DUMMY_PATH);
 
345
                dbus_connection_unref(connection);
 
346
                connection = NULL;
335
347
                return -1;
336
348
        }
337
349
 
340
352
 
341
353
void sap_exit(void)
342
354
{
343
 
        g_dbus_unregister_interface(connection, SAP_DUMMY_PATH, SAP_DUMMY_IFACE);
 
355
        g_dbus_unregister_interface(connection, SAP_DUMMY_PATH,
 
356
                                                        SAP_DUMMY_IFACE);
 
357
 
344
358
        dbus_connection_unref(connection);
345
359
        connection = NULL;
346
360
}