summaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorAnderson Lizardo <anderson.lizardo@openbossa.org>2013-07-19 13:34:09 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2013-07-24 08:41:47 -0700
commitccd0e3783dbfeedd70a94a404580daffac772323 (patch)
tree0991e58287d0f9596bad08fa7f182008a3e9d4a7 /attrib
parent1d4f111fae897e5bbee5733955dd2d75c815e659 (diff)
attrib: Do not use Write Command in gatt_write_char()
Previously, if no callback was given to gatt_write_char(), it was assumed that a "Write Without Response" (which uses Write Command) should be used instead of Write Request. This "shortcut" is unnecessary (there is gatt_write_cmd() for the situations where Write Without Response is required) and just duplicates code. This commit also fixes the few places where gatt_write_cmd() should be used.
Diffstat (limited to 'attrib')
-rw-r--r--attrib/gatt.c22
-rw-r--r--attrib/interactive.c2
2 files changed, 11 insertions, 13 deletions
diff --git a/attrib/gatt.c b/attrib/gatt.c
index d21dd392c..9de07e4e9 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -785,23 +785,21 @@ guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
{
uint8_t *buf;
size_t buflen;
- guint16 plen;
struct write_long_data *long_write;
buf = g_attrib_get_buffer(attrib, &buflen);
- /* Only use Write Request/Command if payload fits on a single transfer,
- * including 3 bytes for the header. */
+ /* Use Write Request if payload fits on a single transfer, including 3
+ * bytes for the header. */
if (vlen <= buflen - 3) {
- if (func)
- plen = enc_write_req(handle, value, vlen, buf,
- buflen);
- else
- plen = enc_write_cmd(handle, value, vlen, buf,
- buflen);
-
- return g_attrib_send(attrib, 0, buf, plen, func,
- user_data, NULL);
+ uint16_t plen;
+
+ plen = enc_write_req(handle, value, vlen, buf, buflen);
+ if (plen == 0)
+ return 0;
+
+ return g_attrib_send(attrib, 0, buf, plen, func, user_data,
+ NULL);
}
/* Write Long Characteristic Values */
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 1f3122fcd..5bd27afa6 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -675,7 +675,7 @@ static void cmd_char_write(int argcp, char **argvp)
gatt_write_char(attrib, handle, value, plen,
char_write_req_cb, NULL);
else
- gatt_write_char(attrib, handle, value, plen, NULL, NULL);
+ gatt_write_cmd(attrib, handle, value, plen, NULL, NULL);
g_free(value);
}