* [PATCH BlueZ 01/10] ATT: Avoid invalid memory access for large PDU
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 02/10] dis: Reduce array size for PnP ID Claudio Takahasi
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patch avoids invalid memory access when decoding ATT read response
PDUs. The ATT_MTU value is a per ATT Bearer value defined by the higher
layer specification.
---
attrib/att.c | 17 +++++++++--------
attrib/att.h | 2 +-
attrib/gatttool.c | 7 +++++--
attrib/interactive.c | 6 ++++--
deviceinfo/deviceinfo.c | 5 +++--
proximity/monitor.c | 7 ++++---
thermometer/thermometer.c | 15 +++++++++------
7 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/attrib/att.c b/attrib/att.c
index c8e2e1d..0550ac1 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -681,22 +681,23 @@ uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset,
return vlen + 1;
}
-uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen)
+ssize_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int vlen)
{
if (pdu == NULL)
- return 0;
+ return -EINVAL;
- if (value == NULL || vlen == NULL)
- return 0;
+ if (value == NULL)
+ return -EINVAL;
if (pdu[0] != ATT_OP_READ_RESP)
- return 0;
+ return -EINVAL;
- memcpy(value, pdu + 1, len - 1);
+ if (vlen < (len - 1))
+ return -ENOBUFS;
- *vlen = len - 1;
+ memcpy(value, pdu + 1, len - 1);
- return len;
+ return len - 1;
}
uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
diff --git a/attrib/att.h b/attrib/att.h
index 144513f..1c1102a 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -234,7 +234,7 @@ uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle,
uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len);
uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset,
uint8_t *pdu, int len);
-uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen);
+ssize_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int vlen);
uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
uint8_t *pdu, int len);
uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu, int len);
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 8a43ec1..c70b1d6 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -227,14 +227,17 @@ static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
uint8_t value[ATT_MAX_MTU];
- int i, vlen;
+ ssize_t vlen;
+ int i;
if (status != 0) {
g_printerr("Characteristic value/descriptor read failed: %s\n",
att_ecode2str(status));
goto done;
}
- if (!dec_read_resp(pdu, plen, value, &vlen)) {
+
+ vlen = dec_read_resp(pdu, plen, value, sizeof(value));
+ if (vlen < 0) {
g_printerr("Protocol error\n");
goto done;
}
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 0a01cdf..1cdbfef 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -275,7 +275,8 @@ static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
uint8_t value[ATT_MAX_MTU];
- int i, vlen;
+ ssize_t vlen;
+ int i;
if (status != 0) {
printf("Characteristic value/descriptor read failed: %s\n",
@@ -283,7 +284,8 @@ static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
return;
}
- if (!dec_read_resp(pdu, plen, value, &vlen)) {
+ vlen = dec_read_resp(pdu, plen, value, sizeof(value));
+ if (vlen < 0) {
printf("Protocol error\n");
return;
}
diff --git a/deviceinfo/deviceinfo.c b/deviceinfo/deviceinfo.c
index 8c3af93..41fc3fc 100644
--- a/deviceinfo/deviceinfo.c
+++ b/deviceinfo/deviceinfo.c
@@ -85,14 +85,15 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
{
struct characteristic *ch = user_data;
uint8_t value[ATT_MAX_MTU];
- int vlen;
+ ssize_t vlen;
if (status != 0) {
error("Error reading PNP_ID value: %s", att_ecode2str(status));
return;
}
- if (!dec_read_resp(pdu, len, value, &vlen)) {
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
error("Error reading PNP_ID: Protocol error");
return;
}
diff --git a/proximity/monitor.c b/proximity/monitor.c
index 98dbcd1..2645321 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -212,20 +212,21 @@ static void tx_power_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
uint8_t value[ATT_MAX_MTU];
- int vlen;
+ ssize_t vlen;
if (status != 0) {
DBG("Tx Power Level read failed: %s", att_ecode2str(status));
return;
}
- if (!dec_read_resp(pdu, plen, value, &vlen)) {
+ vlen = dec_read_resp(pdu, plen, value, sizeof(value));
+ if (vlen < 0) {
DBG("Protocol error");
return;
}
if (vlen != 1) {
- DBG("Invalid length for TX Power value: %d", vlen);
+ DBG("Invalid length for TX Power value: %zd", vlen);
return;
}
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index 85f0811..4a44177 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -299,7 +299,7 @@ static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
struct descriptor *desc = user_data;
uint8_t value[ATT_MAX_MTU];
uint16_t max, min;
- int vlen;
+ ssize_t vlen;
if (status != 0) {
DBG("Valid Range descriptor read failed: %s",
@@ -307,7 +307,8 @@ static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}
- if (!dec_read_resp(pdu, len, value, &vlen)) {
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
DBG("Protocol error\n");
return;
}
@@ -443,7 +444,7 @@ static void read_temp_type_cb(guint8 status, const guint8 *pdu, guint16 len,
struct characteristic *ch = user_data;
struct thermometer *t = ch->t;
uint8_t value[ATT_MAX_MTU];
- int vlen;
+ ssize_t vlen;
if (status != 0) {
DBG("Temperature Type value read failed: %s",
@@ -451,7 +452,8 @@ static void read_temp_type_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}
- if (!dec_read_resp(pdu, len, value, &vlen)) {
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
DBG("Protocol error.");
return;
}
@@ -471,7 +473,7 @@ static void read_interval_cb(guint8 status, const guint8 *pdu, guint16 len,
struct characteristic *ch = user_data;
uint8_t value[ATT_MAX_MTU];
uint16_t interval;
- int vlen;
+ ssize_t vlen;
if (status != 0) {
DBG("Measurement Interval value read failed: %s",
@@ -479,7 +481,8 @@ static void read_interval_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}
- if (!dec_read_resp(pdu, len, value, &vlen)) {
+ vlen = dec_read_resp(pdu, len, value, sizeof(value));
+ if (vlen < 0) {
DBG("Protocol error\n");
return;
}
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 02/10] dis: Reduce array size for PnP ID
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 01/10] ATT: Avoid invalid memory access for large PDU Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 03/10] thermometer: Use GAttrib buffer Claudio Takahasi
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
PnP_ID characteristic is a 7 octets value which includes Vendor ID
source, a Vendor ID, Product ID, and Product Version.
---
deviceinfo/deviceinfo.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/deviceinfo/deviceinfo.c b/deviceinfo/deviceinfo.c
index 41fc3fc..4548553 100644
--- a/deviceinfo/deviceinfo.c
+++ b/deviceinfo/deviceinfo.c
@@ -37,6 +37,8 @@
#include "log.h"
#include "deviceinfo.h"
+#define PNP_ID_SIZE 7
+
struct deviceinfo {
struct btd_device *dev; /* Device reference */
GAttrib *attrib; /* GATT connection */
@@ -84,7 +86,7 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
gpointer user_data)
{
struct characteristic *ch = user_data;
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[PNP_ID_SIZE];
ssize_t vlen;
if (status != 0) {
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 03/10] thermometer: Use GAttrib buffer
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 01/10] ATT: Avoid invalid memory access for large PDU Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 02/10] dis: Reduce array size for PnP ID Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 04/10] gatttool: " Claudio Takahasi
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patch replaces the static local buffer by the GAttrib internal
buffer to temporarily store the output ATT PDU.
---
thermometer/thermometer.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index 4a44177..c2256b6 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -1135,9 +1135,10 @@ static void ind_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
{
struct thermometer *t = user_data;
const struct characteristic *ch;
- uint8_t opdu[ATT_MAX_MTU];
+ uint8_t *opdu;
uint16_t handle, olen;
GSList *l;
+ int plen;
if (len < 3) {
DBG("Bad pdu received");
@@ -1158,7 +1159,8 @@ static void ind_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
else if (g_strcmp0(ch->attr.uuid, MEASUREMENT_INTERVAL_UUID) == 0)
proc_measurement_interval(t, pdu, len);
- olen = enc_confirmation(opdu, sizeof(opdu));
+ opdu = g_attrib_get_buffer(t->attrib, &plen);
+ olen = enc_confirmation(opdu, plen);
if (olen > 0)
g_attrib_send(t->attrib, 0, opdu[0], opdu, olen, NULL, NULL,
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 04/10] gatttool: Use GAttrib buffer
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (2 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 03/10] thermometer: Use GAttrib buffer Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 05/10] thermometer: Reduce the array for Valid Range Claudio Takahasi
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patch replaces the static local buffer by the GAttrib internal
buffer to store temporarly the output ATT PDU.
---
attrib/gatttool.c | 6 ++++--
attrib/interactive.c | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index c70b1d6..1f23522 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -75,8 +75,9 @@ struct characteristic_data {
static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
{
GAttrib *attrib = user_data;
- uint8_t opdu[ATT_MAX_MTU];
+ uint8_t *opdu;
uint16_t handle, i, olen = 0;
+ int plen;
handle = att_get_u16(&pdu[1]);
@@ -100,7 +101,8 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
if (pdu[0] == ATT_OP_HANDLE_NOTIFY)
return;
- olen = enc_confirmation(opdu, sizeof(opdu));
+ opdu = g_attrib_get_buffer(attrib, &plen);
+ olen = enc_confirmation(opdu, plen);
if (olen > 0)
g_attrib_send(attrib, 0, opdu[0], opdu, olen, NULL, NULL, NULL);
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 1cdbfef..3657798 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -101,8 +101,9 @@ static void set_state(enum state st)
static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
{
- uint8_t opdu[ATT_MAX_MTU];
+ uint8_t *opdu;
uint16_t handle, i, olen;
+ int plen;
handle = att_get_u16(&pdu[1]);
@@ -128,7 +129,8 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
if (pdu[0] == ATT_OP_HANDLE_NOTIFY)
return;
- olen = enc_confirmation(opdu, sizeof(opdu));
+ opdu = g_attrib_get_buffer(attrib, &plen);
+ olen = enc_confirmation(opdu, plen);
if (olen > 0)
g_attrib_send(attrib, 0, opdu[0], opdu, olen, NULL, NULL, NULL);
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 05/10] thermometer: Reduce the array for Valid Range
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (3 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 04/10] gatttool: " Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 06/10] thermometer: Reduce the array for temperature type Claudio Takahasi
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
Valid Range descriptor contains two unsigned 16-bits integers
representing the valid range of values that the Measurement Interval
characteristic can support.
---
thermometer/thermometer.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index c2256b6..614da18 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -48,6 +48,8 @@
#define FLOAT_MAX_MANTISSA 16777216 /* 2^24 */
+#define VALID_RANGE_DESC_SIZE 4
+
struct thermometer {
DBusConnection *conn; /* The connection to the bus */
struct btd_device *dev; /* Device reference */
@@ -297,7 +299,7 @@ static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
gpointer user_data)
{
struct descriptor *desc = user_data;
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[VALID_RANGE_DESC_SIZE];
uint16_t max, min;
ssize_t vlen;
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 06/10] thermometer: Reduce the array for temperature type
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (4 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 05/10] thermometer: Reduce the array for Valid Range Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 07/10] thermometer: Reduce array size for Measurement Interval Claudio Takahasi
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
Temperature Type characteristic is a 8-bits value used to describe
the type of temperature measurement in relation to the location on the
human body.
---
thermometer/thermometer.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index 614da18..914f77c 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -49,6 +49,7 @@
#define FLOAT_MAX_MANTISSA 16777216 /* 2^24 */
#define VALID_RANGE_DESC_SIZE 4
+#define TEMPERATURE_TYPE_SIZE 1
struct thermometer {
DBusConnection *conn; /* The connection to the bus */
@@ -445,7 +446,7 @@ static void read_temp_type_cb(guint8 status, const guint8 *pdu, guint16 len,
{
struct characteristic *ch = user_data;
struct thermometer *t = ch->t;
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[TEMPERATURE_TYPE_SIZE];
ssize_t vlen;
if (status != 0) {
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 07/10] thermometer: Reduce array size for Measurement Interval
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (5 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 06/10] thermometer: Reduce the array for temperature type Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 08/10] proximity: Reduce array size for Tx Power Level Claudio Takahasi
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
Measurement Interval is a 16-bits value characteristic used to enable
and control the interval between consecutive temperature measurements.
---
thermometer/thermometer.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index 914f77c..087662e 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -50,6 +50,7 @@
#define VALID_RANGE_DESC_SIZE 4
#define TEMPERATURE_TYPE_SIZE 1
+#define MEASUREMENT_INTERVAL_SIZE 2
struct thermometer {
DBusConnection *conn; /* The connection to the bus */
@@ -474,7 +475,7 @@ static void read_interval_cb(guint8 status, const guint8 *pdu, guint16 len,
gpointer user_data)
{
struct characteristic *ch = user_data;
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[MEASUREMENT_INTERVAL_SIZE];
uint16_t interval;
ssize_t vlen;
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 08/10] proximity: Reduce array size for Tx Power Level
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (6 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 07/10] thermometer: Reduce array size for Measurement Interval Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 09/10] generic attribute: Use GAttrib buffer Claudio Takahasi
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
Tx Power Level characteristic is a signed 8-bits integer which reports
the current transmit power level.
---
proximity/monitor.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/proximity/monitor.c b/proximity/monitor.c
index 2645321..f22d6f4 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -55,6 +55,7 @@
#define POWER_LEVEL_CHR_UUID 0x2A07
#define IMMEDIATE_TIMEOUT 5
+#define TX_POWER_SIZE 1
enum {
ALERT_NONE = 0,
@@ -211,7 +212,7 @@ static int write_alert_level(struct monitor *monitor)
static void tx_power_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[TX_POWER_SIZE];
ssize_t vlen;
if (status != 0) {
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 09/10] generic attribute: Use GAttrib buffer
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (7 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 08/10] proximity: Reduce array size for Tx Power Level Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-20 17:27 ` [PATCH BlueZ 10/10] attrib-server: Fix MTU for GATT Claudio Takahasi
2012-06-27 12:51 ` [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Johan Hedberg
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patch replaces the static local buffer by the GAttrib internal
buffer to temporarily store the output ATT PDU.
---
attrib/client.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/attrib/client.c b/attrib/client.c
index 8d119df..a90f22b 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -269,9 +269,10 @@ static void events_handler(const uint8_t *pdu, uint16_t len,
struct gatt_service *gatt = user_data;
struct characteristic *chr;
GSList *l;
- uint8_t opdu[ATT_MAX_MTU];
+ uint8_t *opdu;
guint handle;
uint16_t olen;
+ int plen;
if (len < 3) {
DBG("Malformed notification/indication packet (opcode 0x%02x)",
@@ -295,7 +296,8 @@ static void events_handler(const uint8_t *pdu, uint16_t len,
switch (pdu[0]) {
case ATT_OP_HANDLE_IND:
- olen = enc_confirmation(opdu, sizeof(opdu));
+ opdu = g_attrib_get_buffer(gatt->attrib, &plen);
+ olen = enc_confirmation(opdu, plen);
g_attrib_send(gatt->attrib, 0, opdu[0], opdu, olen,
NULL, NULL, NULL);
case ATT_OP_HANDLE_NOTIFY:
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH BlueZ 10/10] attrib-server: Fix MTU for GATT
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (8 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 09/10] generic attribute: Use GAttrib buffer Claudio Takahasi
@ 2012-06-20 17:27 ` Claudio Takahasi
2012-06-27 12:51 ` [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Johan Hedberg
10 siblings, 0 replies; 12+ messages in thread
From: Claudio Takahasi @ 2012-06-20 17:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patch changes the size of the input and output buffers to the same size of
the channel MTU. The channel MTU, in turn, is the L2CAP MTU for BR/EDR
channels, and the ATT MTU for LE channels. This value can change between calls
to channel_handler if a GATT MTU exchange procedure is performed, which is only
supported by LE channels.
---
src/attrib-server.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 5adbf92..9064d15 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -910,7 +910,7 @@ static void channel_handler(const uint8_t *ipdu, uint16_t len,
gpointer user_data)
{
struct gatt_channel *channel = user_data;
- uint8_t opdu[ATT_MAX_MTU], value[ATT_MAX_MTU];
+ uint8_t opdu[channel->mtu], value[ATT_MAX_MTU];
uint16_t length, start, end, mtu, offset;
bt_uuid_t uuid;
uint8_t status = 0;
--
1.7.8.6
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH BlueZ 00/10] ATT MTU: cosmetic changes
2012-06-20 17:27 [PATCH BlueZ 00/10] ATT MTU: cosmetic changes Claudio Takahasi
` (9 preceding siblings ...)
2012-06-20 17:27 ` [PATCH BlueZ 10/10] attrib-server: Fix MTU for GATT Claudio Takahasi
@ 2012-06-27 12:51 ` Johan Hedberg
10 siblings, 0 replies; 12+ messages in thread
From: Johan Hedberg @ 2012-06-27 12:51 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
Hi Claudio,
On Wed, Jun 20, 2012, Claudio Takahasi wrote:
> This patch series contains minor improvements related to ATT MTU and
> GAttrib buffer usage.
>
> Claudio Takahasi (10):
> ATT: Avoid invalid memory access for large PDU
> dis: Reduce array size for PnP ID
> thermometer: Use GAttrib buffer
> gatttool: Use GAttrib buffer
> thermometer: Reduce the array for Valid Range
> thermometer: Reduce the array for temperature type
> thermometer: Reduce array size for Measurement Interval
> proximity: Reduce array size for Tx Power Level
> generic attribute: Use GAttrib buffer
> attrib-server: Fix MTU for GATT
>
> attrib/att.c | 17 +++++++++--------
> attrib/att.h | 2 +-
> attrib/client.c | 6 ++++--
> attrib/gatttool.c | 13 +++++++++----
> attrib/interactive.c | 12 ++++++++----
> deviceinfo/deviceinfo.c | 9 ++++++---
> proximity/monitor.c | 10 ++++++----
> src/attrib-server.c | 2 +-
> thermometer/thermometer.c | 31 ++++++++++++++++++++-----------
> 9 files changed, 64 insertions(+), 38 deletions(-)
All patches in this set have been applied. Thanks.
Be careful with the commit message width in the future, it should be max
72 (I had to fix this at least in one patch).
Johan
^ permalink raw reply [flat|nested] 12+ messages in thread