summaryrefslogtreecommitdiff
path: root/patches/collateral-evolutions/network/16-bluetooth/net_bluetooth_hidp_core.patch
blob: 068243f1ae39e54c10b8b79a1ef372c3085e9e79 (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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -268,6 +268,7 @@ static int hidp_hidinput_event(struct in
 	return hidp_send_report(session, field->report);
 }
 
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
 static int hidp_get_raw_report(struct hid_device *hid,
 		unsigned char report_number,
 		unsigned char *data, size_t count,
@@ -352,6 +353,7 @@ err:
 	mutex_unlock(&session->report_mutex);
 	return ret;
 }
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38)) */
 
 static int hidp_set_raw_report(struct hid_device *hid, unsigned char reportnum,
 			       unsigned char *data, size_t count,
@@ -418,6 +420,7 @@ err:
 	return ret;
 }
 
+#if defined(CPTCFG_BACKPORT_OPTION_BT_SOCK_CREATE_NEEDS_KERN)
 static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count,
 		unsigned char report_type)
 {
@@ -475,6 +478,16 @@ err:
 	mutex_unlock(&session->report_mutex);
 	return ret;
 }
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
+static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count)
+{
+	if (hidp_send_ctrl_message(hid->driver_data,
+			HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE,
+			data, count))
+		return -ENOMEM;
+	return count;
+}
+#endif
 
 static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum,
 			    __u8 *buf, size_t len, unsigned char rtype,
@@ -786,6 +799,87 @@ static void hidp_close(struct hid_device
 {
 }
 
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27))
+static const struct {
+	__u16 idVendor;
+	__u16 idProduct;
+	unsigned quirks;
+} hidp_blacklist[] = {
+	/* Apple wireless Mighty Mouse */
+	{ 0x05ac, 0x030c, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
+
+	{ }	/* Terminating entry */
+};
+static void hidp_setup_quirks(struct hid_device *hid)
+{
+	unsigned int n;
+
+	for (n = 0; hidp_blacklist[n].idVendor; n++)
+		if (hidp_blacklist[n].idVendor == le16_to_cpu(hid->vendor) &&
+				hidp_blacklist[n].idProduct == le16_to_cpu(hid->product))
+			hid->quirks = hidp_blacklist[n].quirks;
+}
+
+static int hidp_setup_hid(struct hidp_session *session,
+			  struct hidp_connadd_req *req)
+{
+	struct hid_device *hid;
+	struct hid_report *report;
+	bdaddr_t src, dst;
+	unsigned char *buf;
+
+	buf = kmalloc(req->rd_size, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	if (copy_from_user(buf, req->rd_data, req->rd_size)) {
+		kfree(buf);
+		return -EFAULT;
+	}
+
+	hid = hid_parse_report(buf, req->rd_size);
+	kfree(buf);
+	if (!session->hid)
+		return -EINVAL;
+
+	session->hid = hid;
+
+	hid->driver_data = session;
+
+	baswap(&src, &bt_sk(session->ctrl_sock->sk)->src);
+	baswap(&dst, &bt_sk(session->ctrl_sock->sk)->dst);
+
+	hid->bus     = BUS_BLUETOOTH;
+	hid->vendor  = req->vendor;
+	hid->product = req->product;
+	hid->version = req->version;
+	hid->country = req->country;
+
+	strlcpy(hid->name, req->name, 128);
+	strlcpy(hid->phys, batostr(&src), 64);
+	strlcpy(hid->uniq, batostr(&dst), 64);
+
+	hid->dev = hidp_get_device(session);
+	hid->hid_open  = hidp_open;
+	hid->hid_close = hidp_close;
+
+	hid->hidinput_input_event = hidp_hidinput_event;
+
+	hidp_setup_quirks(hid);
+
+	list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
+		hidp_send_report(session, report);
+
+	list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
+		hidp_send_report(session, report);
+
+	if (hidinput_connect(hid) == 0)
+		hid->claimed |= HID_CLAIMED_INPUT;
+
+	return 0;
+}
+#else
+
 static int hidp_parse(struct hid_device *hid)
 {
 	struct hidp_session *session = hid->driver_data;
@@ -865,7 +959,9 @@ static int hidp_setup_hid(struct hidp_se
 	hid->dev.parent = &session->conn->hcon->dev;
 	hid->ll_driver = &hidp_hid_driver;
 
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
 	hid->hid_get_raw_report = hidp_get_raw_report;
+#endif
 	hid->hid_output_raw_report = hidp_output_raw_report;
 
 	/* True if device is blacklisted in drivers/hid/hid-core.c */
@@ -883,6 +979,7 @@ fault:
 
 	return err;
 }
+#endif
 
 /* initialize session devices */
 static int hidp_session_dev_init(struct hidp_session *session,
@@ -945,10 +1042,17 @@ static int hidp_session_dev_add(struct h
 /* remove HID/input devices from their bus systems */
 static void hidp_session_dev_del(struct hidp_session *session)
 {
-	if (session->hid)
+	if (session->hid) {
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
 		hid_destroy_device(session->hid);
-	else if (session->input)
+#else
+		if (session->hid->claimed & HID_CLAIMED_INPUT)
+			hidinput_disconnect(session->hid);
+		hid_free_device(session->hid);
+#endif
+	} else if (session->input) {
 		input_unregister_device(session->input);
+	}
 }
 
 /*