Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / android / tester-map-client.c
1 /*
2  * Copyright (C) 2014 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <stdbool.h>
19
20 #include "emulator/bthost.h"
21 #include "src/shared/tester.h"
22 #include "src/shared/queue.h"
23 #include "tester-main.h"
24
25 static struct queue *list = NULL; /* List of map client test cases */
26
27 #define INST0_ID 0
28 #define INST1_ID 1
29
30 #define sdp_rsp_pdu     0x07, \
31                         0x00, 0x00, \
32                         0x00, 0xb5, \
33                         0x00, 0xb2, \
34                         0x35, 0xb0, 0x36, 0x00, 0x56, 0x09, 0x00, 0x00, 0x0a, \
35                         0x00, 0x01, 0x00, 0x09, 0x09, 0x00, 0x01, 0x35, 0x03, \
36                         0x19, 0x11, 0x32, 0x09, 0x00, 0x04, 0x35, 0x11, 0x35, \
37                         0x03, 0x19, 0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, \
38                         0x08, 0x04, 0x35, 0x03, 0x19, 0x00, 0x08, 0x09, 0x00, \
39                         0x05, 0x35, 0x03, 0x19, 0x10, 0x02, 0x09, 0x00, 0x09, \
40                         0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x34, 0x09, 0x01, \
41                         0x01, 0x09, 0x01, 0x00, 0x25, 0x0c, 0x4d, 0x41, 0x50, \
42                         0x20, 0x53, 0x4d, 0x53, 0x2f, 0x4d, 0x4d, 0x53, 0x00, \
43                         0x09, 0x03, 0x15, 0x08, 0x00, 0x09, 0x03, 0x16, 0x08, \
44                         0x0e, 0x36, 0x00, 0x54, 0x09, 0x00, 0x00, 0x0a, 0x00, \
45                         0x01, 0x00, 0x0a, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, \
46                         0x11, 0x32, 0x09, 0x00, 0x04, 0x35, 0x11, 0x35, 0x03, \
47                         0x19, 0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, 0x08, \
48                         0x05, 0x35, 0x03, 0x19, 0x00, 0x08, 0x09, 0x00, 0x05, \
49                         0x35, 0x03, 0x19, 0x10, 0x02, 0x09, 0x00, 0x09, 0x35, \
50                         0x08, 0x35, 0x06, 0x19, 0x11, 0x34, 0x09, 0x01, 0x01, \
51                         0x09, 0x01, 0x00, 0x25, 0x0a, 0x4d, 0x41, 0x50, 0x20, \
52                         0x45, 0x4d, 0x41, 0x49, 0x4c, 0x00, 0x09, 0x03, 0x15, \
53                         0x08, 0x01, 0x09, 0x03, 0x16, 0x08, 0x01, \
54                         0x00
55
56 static const struct pdu_set pdus[] = {
57         { end_pdu, raw_pdu(sdp_rsp_pdu) },
58         { end_pdu, end_pdu },
59 };
60
61 static struct emu_l2cap_cid_data cid_data = {
62         .pdu = pdus,
63 };
64
65 static bt_bdaddr_t emu_remote_bdaddr_val = {
66         .address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
67 };
68
69 static struct emu_set_l2cap_data l2cap_sdp_setup_data = {
70         .psm = 1,
71         .func = tester_generic_connect_cb,
72         .user_data = &cid_data,
73 };
74
75 /* TODO define all parameters according to specification document */
76 static btmce_mas_instance_t remote_map_inst_sms_mms_email_val[] = {
77         { INST0_ID, 4, 14, "MAP SMS/MMS" },
78         { INST1_ID, 5, 1, "MAP EMAIL" },
79 };
80
81 static void map_client_cid_hook_cb(const void *data, uint16_t len,
82                                                                 void *user_data)
83 {
84         /* TODO extend if needed */
85 }
86
87 static void map_client_conn_cb(uint16_t handle, void *user_data)
88 {
89         struct test_data *data = tester_get_data();
90         struct bthost *bthost = hciemu_client_get_host(data->hciemu);
91
92         tester_print("New connection with handle 0x%04x", handle);
93
94         if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
95                 tester_warn("Not handled device type.");
96                 return;
97         }
98
99         cid_data.cid = 0x0040;
100         cid_data.handle = handle;
101
102         bthost_add_cid_hook(bthost, handle, cid_data.cid,
103                                         map_client_cid_hook_cb, &cid_data);
104 }
105
106 static void map_client_get_instances_action(void)
107 {
108         struct test_data *data = tester_get_data();
109         struct step *current_data_step = queue_peek_head(data->steps);
110         bt_bdaddr_t *bd_addr = current_data_step->set_data;
111         struct step *step = g_new0(struct step, 1);
112
113         step->action_status =
114                 data->if_map_client->get_remote_mas_instances(bd_addr);
115
116         schedule_action_verification(step);
117 }
118
119 static struct test_case test_cases[] = {
120         TEST_CASE_BREDRLE("MAP Client Init", ACTION_SUCCESS(dummy_action, NULL),
121         ),
122         TEST_CASE_BREDRLE("MAP Client - Get mas instances success",
123                 ACTION_SUCCESS(bluetooth_enable_action, NULL),
124                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
125                 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
126                 ACTION_SUCCESS(emu_add_l2cap_server_action,
127                                                         &l2cap_sdp_setup_data),
128                 ACTION_SUCCESS(emu_set_connect_cb_action, map_client_conn_cb),
129                 ACTION_SUCCESS(map_client_get_instances_action,
130                                                         &emu_remote_bdaddr_val),
131                 CALLBACK_MAP_CLIENT_REMOTE_MAS_INSTANCE(BT_STATUS_SUCCESS, NULL,
132                                         2, remote_map_inst_sms_mms_email_val),
133                 ACTION_SUCCESS(bluetooth_disable_action, NULL),
134                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
135         ),
136 };
137
138 struct queue *get_map_client_tests(void)
139 {
140         uint16_t i = 0;
141
142         list = queue_new();
143
144         for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
145                 queue_push_tail(list, &test_cases[i]);
146
147         return list;
148 }
149
150 void remove_map_client_tests(void)
151 {
152         queue_destroy(list, NULL);
153 }