* Re: Any update on software caused connection abort issue??
From: john michelle @ 2010-07-22 14:17 UTC (permalink / raw)
To: Lukas; +Cc: linux-bluetooth
In-Reply-To: <201007211753.26822.LuHe@gmx.at>
Hi Lukas,
> It would be great to see this problem fixed soon, because it's nearly
> impossible to use bluetooth on my PC.
I think it's useless to get any reply from this mailing list, i have
been reporting this
Problem for a long time and no one simply cares.
John
On Wed, Jul 21, 2010 at 5:53 PM, Lukas <LuHe@gmx.at> wrote:
> Hello,
>
> On Wednesday 21 July 2010 17:35:15 john michelle wrote:
>> Any update on software caused connection abort issue
>
> I also noticed this error when I used the software suite Series60-Remote to
> connect to my mobile phone.
>
> Shortly after the connection establishment is completed I get the error
> message "software caused connection abort" and the device gets disconnected.
>
> I also see the HCI reset, as described below, when I try to investigate this
> error using hcidump.
>
> The software uses the RFCOMM protocol for the connection.
> I use an USB bluetooth adapter from Belkin, lsusb reports the following device
> id:
> ID 050d:0131 Belkin Components Bluetooth Device with trace filter
>
> This bug happens with the following kernel:
> root@erde ~ # rpm -q kernel bluez
> kernel-2.6.33.6-147.fc13.x86_64
> bluez-4.64-1.fc13.x86_64
>
> You can also look at this thread in my mailing list for further informations:
> https://sourceforge.net/mailarchive/forum.php?thread_name=201007192136.27723.LuHe%40gmx.at&forum_name=series60-
> remote-devel
>
> It would be great to see this problem fixed soon, because it's nearly
> impossible to use bluetooth on my PC.
>
> Thanks,
> Lukas
>
>> >>On Wed, Jun 23, 2010 at 12:48 AM, john michelle <jhnmichelle@gmail.com>
> wrote:
>> >> Dear Bluetooth community,
>> >>
>> >> You are committing version after version and have time to add new
>> >> Features and the core stack have a major bug (software Caused
>> >> connection abort) that i
>> >> Have reported on the 7th of may the problem seems to be either in the
>> >> usb part of the
>> >> Kernel or the bluez stack, i am no kernel engineer so i came directly
>> >> to you for reporting
>> >> This problem and my requests to look into this problem are just
>> >> ignored. this is a blocker
>> >> Issue that would prevent and discourage any one from developing
>> >> application that rely on
>> >> Bluez sco capabilities, since during transmission the above mentioned
>> >> error just occurs.
>> >> I hope that my voice is heared and i would get a reply from the bluez
>> >> community.
>> >>
>> >> John
>> >>
>> >> On Wed, Jun 16, 2010 at 3:11 PM, john michelle <jhnmichelle@gmail.com>
> wrote:
>> >>> On Sun, May 30, 2010 at 1:12 PM, john michelle <jhnmichelle@gmail.com>
> wrote:
>> >>>> Hi Gustavo,
>> >>>>
>> >>>>>> Please post the output of hcidump when the connection abort happens.
>> >>>>
>> >>>> Below is the output of hcidump the moments the software caused
>> >>>> connection abort
>> >>>>
>> >>>> Dongle 1:
>> >>>>> HCI Event: Number of Completed Packets (0x13) plen 5
>> >>>>
>> >>>> . * . . .
>> >>>> < HCI Command: Reset (0x03|0x0003) plen 0
>> >>>> device: disconnected
>> >>>>
>> >>>> Dongle 2:
>> >>>>> HCI Event: Number of Completed Packets (0x13) plen 5
>> >>>>
>> >>>> . * . . .
>> >>>> < HCI Command: Reset (0x03|0x0003) plen 0
>> >>>> device: disconnected
>> >>>>
>> >>>>
>> >>>> I think something triggers hci reset which causes this problem, but
>> >>>> what exactly Triggers it i don't know.
>> >>>>
>> >>>>
>> >>>> John
>> >>>
>> >>> Hi all,
>> >>>
>> >>> Is anyone going to give this problem a try, it has been like a month
>> >>> now This is a real problem in the bluez stack and someone have to look
>> >>> in this Issue.
>> >>>
>> >>> John
>> >>>
>> >>>> On Mon, May 17, 2010 at 5:21 PM, john michelle <jhnmichelle@gmail.com>
> wrote:
>> >>>>>> Hi Jonh,
>> >>>>>>
>> >>>>>> First of all, don't do top posting in this mailing list. ;)
>> >>>>>
>> >>>>> Thanks for the advise , will keep that in mind for future posts.
>> >>>>>
>> >>>>>> In which bluez/kernel version the problem started? Any hardware
>> >>>>>> update during this time? The problem happens when you are already
>> >>>>>> tranfering SCO data?
>> >>>>>
>> >>>>> I tried bluez versions 3.XX and kernel 2.6.26(I think) the problem
>> >>>>> occurs and the kernel panics with no core dumps.then i tried with
>> >>>>> bluez 4.53-4.62 with
>> >>>>> Kernel 2.6.31 and 2.6.32. the connection abort problem occurs but the
>> >>>>> kernel doesn't
>> >>>>> Panic. regarding the hardware update you mean the dongle or the
>> >>>>> box.Anyway i changed both and tried different box's, this even
>> >>>>> happens on a box with 2 giga ram
>> >>>>> And core2 processor . as for the dongles i am using trust
>> >>>>>
>> >>>>> http://www.twenga.co.uk/prices-Bluetooth-2-USB-Adapter-10m-BT-2250p-T
>> >>>>> RUST-Wireless-network-card-adapter-176178-0
>> >>>>>
>> >>>>> and also using no name dongles all the same problem.
>> >>>>>
>> >>>>>> Please post the output of hcidump when the connection abort happens.
>> >>>>>
>> >>>>> well that is going to be a hard one since i have more than one dongle
>> >>>>> in place And very hard to predict which one will crash.i will work
>> >>>>> on this and update You as soon as i have the hcidump log.
>> >>>>>
>> >>>>>> I tried reproduce this issue in L2CAP but it is a bit hard, lets
>> >>>>>> say it happen once in a thousand, so it's not easy to track it. I
>> >>>>>> have to try reproduce that using the SCO, but I'm not used to that
>> >>>>>> layer yet. ;)
>> >>>>>
>> >>>>> I hoped that it happens 1 in 1000 in SCO , but it actually happens 1
>> >>>>> in 15
>> >>>>>
>> >>>>>
>> >>>>> John
>> >>>>>
>> >>>>>> Regards,
>> >>>>>>
>> >>>>>>> John
>> >>>>>>>
>> >>>>>>> On Fri, May 7, 2010 at 3:53 PM, Gustavo F. Padovan
> <gustavo@padovan.org> wrote:
>> >>>>>>> > * john michelle <jhnmichelle@gmail.com> [2010-05-07 15:49:05
> -0400]:
>> >>>>>>> >> Hi Bluetooth hackers,
>> >>>>>>> >>
>> >>>>>>> >> i am having this consistent problem with bluez , from time to
>> >>>>>>> >> time i get the error Software caused connection abort (103 )
>> >>>>>>> >> And the bluetooth stick seems to disconnect and reconnects. this
>> >>>>>>> >> happens during an sco connection and it occurs even
>> >>>>>>> >> More when i am having the voice stream comming through the
>> >>>>>>> >> internet rather than the lan.i don't know what exact
>> >>>>>>> >> Details you need to solve this problem please tell me and i will
>> >>>>>>> >> give you an immediate reply . i have linux kernel 2.6.33 and
>> >>>>>>> >> bluez 4.62
>> >>>>>>> >
>> >>>>>>> > I get the same problem sometimes when testing ERTM with l2test.
>> >>>>>>> > So the problem is on l2cap too. I didn't have time to debug this
>> >>>>>>> > yet. Now that someone else have confirmed it too, I'll to take a
>> >>>>>>> > look at the problem.
>> >>>>>>
>> >>>>>> --
>> >>>>>> Gustavo F. Padovan
>> >>>>>> http://padovan.org
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
>> in the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply
* Re: [PATCH 1/1] Bluetooth: hidp: Add support for hidraw HIDIOCGFEATURE and HIDIOCSFEATURE
From: Jiri Kosina @ 2010-07-22 14:14 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Alan Ott, David S Miller, Michael Poole, Bastien Nocera,
Eric Dumazet, linux-bluetooth, linux-kernel, netdev
In-Reply-To: <1278696815.10421.137.camel@localhost.localdomain>
On Fri, 9 Jul 2010, Marcel Holtmann wrote:
> > >>> what is usb-hid.ko doing here? I would expect a bunch of code
> > >>> duplication with minor difference between USB and Bluetooth.
> > >>>
> > >> usbhid doesn't have a lot of code for hidraw. Two functions are involved:
> > >> usbhid_output_raw_report()
> > >> - calls usb_control_msg() with Get_Report
> > >> usbhid_get_raw_report()
> > >> - calls usb_control_msg() with Set_Report
> > >> OR
> > >> - calls usb_interrupt_msg() on the Ouput pipe.
> > >>
> > >> This is of course easier than bluetooth because usb_control_msg() is
> > >> synchronous, even when requesting reports, mostly because of the nature
> > >> of USB, where the request and response are part of the same transfer.
> > >>
> > >> For Bluetooth, it's a bit more complicated since the kernel treats it
> > >> more like a networking interface (and indeed it is). My understanding is
> > >> that to make a synchronous transfer in bluetooth, one must:
> > >> - send the request packet
> > >> - block (wait_event_*())
> > >> - when the response is received in the input handler, wake_up_*().
> > >>
> > >> There's not really any code duplication, mostly because initiating
> > >> synchronous USB transfers (input and output) is easy (because of the
> > >> usb_*_msg() functions), while making synchronous Bluetooth transfers
> > >> must be done manually. If there's a nice, convenient, synchronous
> > >> function in Bluetooth similar to usb_control_msg() that I've missed,
> > >> then let me know, as it would simplify this whole thing.
> > >>
> > > there is not and I don't think we ever get one. My question here was
> > > more in the direction why HID core is doing these synchronously in the
> > > first place. Especially since USB can do everything async as well.
> >
> > I'm open to suggestions. The way I see it is from a user space
> > perspective. With Get_Feature being on an ioctl(), I don't see any clean
> > way to do it other than synchronously. Other operating systems (I can
> > say for sure Windows, Mac OS X, and FreeBSD) handle Get/Set Feature the
> > same way (synchronously) from user space.
> >
> > You seem to be proposing an asynchronous interface. What would that look
> > like from user space?
>
> not necessarily from user space, but at least from HID core to HIDP and
> usb-hid transports. At least that is what I would expect, Jiri?
Sorry for this taking too long (vacations, conferences, you name it) for
me to respond.
As all the _raw() callbacks are purely intended for userspace interaction
anyway, it's perfectly fine (and in fact desirable) for the low-level
transport drivers to perform these operations synchronously (and that's
what USB implementation does as well).
Marcel, if your opposition to synchronous interface is strong, we'll have
to think about other aproaches, but from my POV, the patch is fine as-is
for Bluetooth.
Thanks,
--
Jiri Kosina
SUSE Labs, Novell Inc.
^ permalink raw reply
* Re: [PATCH] Fix query for VCARD listing (work phone issue)
From: Johan Hedberg @ 2010-07-22 12:14 UTC (permalink / raw)
To: Radoslaw Jablonski; +Cc: linux-bluetooth
In-Reply-To: <1279800371-24342-1-git-send-email-ext-jablonski.radoslaw@nokia.com>
Hi Radek,
On Thu, Jul 22, 2010, Radoslaw Jablonski wrote:
> Fixed tracker query for VCARD listing - previously contacts with only
> work phone filled were missing in query result (and in vcard listing).
> Now if mobile/home phone number is not available, then trying to get
> work phone number.
> ---
> plugins/phonebook-tracker.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
> index ee072d3..41d7fde 100644
> --- a/plugins/phonebook-tracker.c
> +++ b/plugins/phonebook-tracker.c
> @@ -72,6 +72,10 @@
> "WHERE { " \
> "?c a nco:PersonContact . " \
> "OPTIONAL { ?c nco:hasPhoneNumber ?h . } " \
> + "OPTIONAL { " \
> + "?c nco:hasAffiliation ?a . " \
> + "?a nco:hasPhoneNumber ?h . " \
> + "} " \
> "}"
>
> #define MISSED_CALLS_QUERY \
Thanks for the patch. It's now upstream.
Johan
^ permalink raw reply
* [PATCH] Fix query for VCARD listing (work phone issue)
From: Radoslaw Jablonski @ 2010-07-22 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Radoslaw Jablonski
Fixed tracker query for VCARD listing - previously contacts with only
work phone filled were missing in query result (and in vcard listing).
Now if mobile/home phone number is not available, then trying to get
work phone number.
---
plugins/phonebook-tracker.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index ee072d3..41d7fde 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -72,6 +72,10 @@
"WHERE { " \
"?c a nco:PersonContact . " \
"OPTIONAL { ?c nco:hasPhoneNumber ?h . } " \
+ "OPTIONAL { " \
+ "?c nco:hasAffiliation ?a . " \
+ "?a nco:hasPhoneNumber ?h . " \
+ "} " \
"}"
#define MISSED_CALLS_QUERY \
--
1.7.0.4
^ permalink raw reply related
* Re: CTP profile Support of BlueZ
From: Johan Hedberg @ 2010-07-22 9:43 UTC (permalink / raw)
To: zhang wei; +Cc: linux-bluetooth
In-Reply-To: <003601cb297e$aa3a0ba0$feae22e0$@com>
Hi Wei,
On Thu, Jul 22, 2010, zhang wei wrote:
> I have seen the CTP in the supported profile list of bluez.
Where is this list?
Johan
^ permalink raw reply
* CTP profile Support of BlueZ
From: zhang wei @ 2010-07-22 9:17 UTC (permalink / raw)
To: linux-bluetooth
Hi Guys,
I have seen the CTP in the supported profile list of bluez.
However, I can't the source code in the BlueZ.
Why? Thanks ahead.
Wei
^ permalink raw reply
* [PATCH 60/60] Change variable name for MCAP Instances
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-11-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 46 +++++++++++++++++++++++-----------------------
mcap/mcap_lib.h | 6 +++---
2 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 5369328..6155f0a 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1987,51 +1987,51 @@ struct mcap_instance *mcap_create_instance(struct btd_adapter *btd_adapter,
return ms;
}
-void mcap_release_instance(struct mcap_instance *ms)
+void mcap_release_instance(struct mcap_instance *mi)
{
GSList *l;
- if (!ms)
+ if (!mi)
return;
- if (ms->ccio) {
- g_io_channel_shutdown(ms->ccio, TRUE, NULL);
- g_io_channel_unref(ms->ccio);
- ms->ccio = NULL;
+ if (mi->ccio) {
+ g_io_channel_shutdown(mi->ccio, TRUE, NULL);
+ g_io_channel_unref(mi->ccio);
+ mi->ccio = NULL;
}
- if (ms->dcio) {
- g_io_channel_shutdown(ms->dcio, TRUE, NULL);
- g_io_channel_unref(ms->dcio);
- ms->dcio = NULL;
+ if (mi->dcio) {
+ g_io_channel_shutdown(mi->dcio, TRUE, NULL);
+ g_io_channel_unref(mi->dcio);
+ mi->dcio = NULL;
}
- for (l = ms->mcls; l; l = l->next) {
+ for (l = mi->mcls; l; l = l->next) {
mcap_mcl_shutdown(l->data);
mcap_mcl_unref(l->data);
}
- g_slist_free(ms->mcls);
- ms->mcls = NULL;
+ g_slist_free(mi->mcls);
+ mi->mcls = NULL;
- for (l = ms->cached; l; l = l->next)
+ for (l = mi->cached; l; l = l->next)
mcap_mcl_unref(l->data);
- g_slist_free(ms->cached);
- ms->cached = NULL;
+ g_slist_free(mi->cached);
+ mi->cached = NULL;
- g_free(ms);
+ g_free(mi);
}
-uint16_t mcap_get_ctrl_psm(struct mcap_instance *ms, GError **err)
+uint16_t mcap_get_ctrl_psm(struct mcap_instance *mi, GError **err)
{
uint16_t lpsm;
- if (!(ms && ms->ccio)) {
+ if (!(mi && mi->ccio)) {
g_set_error(err, MCAP_ERROR, MCAP_ERROR_INVALID_ARGS,
"Invalid MCAP instance");
return 0;
}
- bt_io_get(ms->ccio, BT_IO_L2CAP, err,
+ bt_io_get(mi->ccio, BT_IO_L2CAP, err,
BT_IO_OPT_PSM, &lpsm,
BT_IO_OPT_INVALID);
if (*err)
@@ -2039,17 +2039,17 @@ uint16_t mcap_get_ctrl_psm(struct mcap_instance *ms, GError **err)
return lpsm;
}
-uint16_t mcap_get_data_psm(struct mcap_instance *ms, GError **err)
+uint16_t mcap_get_data_psm(struct mcap_instance *mi, GError **err)
{
uint16_t lpsm;
- if (!(ms && ms->dcio)) {
+ if (!(mi && mi->dcio)) {
g_set_error(err, MCAP_ERROR, MCAP_ERROR_INVALID_ARGS,
"Invalid MCAP instance");
return 0;
}
- bt_io_get(ms->dcio, BT_IO_L2CAP, err,
+ bt_io_get(mi->dcio, BT_IO_L2CAP, err,
BT_IO_OPT_PSM, &lpsm,
BT_IO_OPT_INVALID);
if (*err)
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index fa62cbe..b6286a1 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -158,10 +158,10 @@ struct mcap_instance *mcap_create_instance(struct btd_adapter *btd_adapter,
gpointer user_data,
GError **gerr);
-void mcap_release_instance(struct mcap_instance *ms);
+void mcap_release_instance(struct mcap_instance *mi);
-uint16_t mcap_get_ctrl_psm(struct mcap_instance *ms, GError **err);
-uint16_t mcap_get_data_psm(struct mcap_instance *ms, GError **err);
+uint16_t mcap_get_ctrl_psm(struct mcap_instance *mi, GError **err);
+uint16_t mcap_get_data_psm(struct mcap_instance *mi, GError **err);
#ifdef __cplusplus
}
--
1.6.3.3
^ permalink raw reply related
* [PATCH 59/60] Remove "req" word from MCAP API
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-10-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 24 ++++++++++++------------
mcap/mcap_lib.h | 10 +++++-----
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index b3017fb..5369328 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -307,8 +307,8 @@ int mcap_send_data(int sock, const uint8_t *buf, uint32_t size)
return 0;
}
-static int mcap_send_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc, uint16_t mdl,
- uint8_t *data, size_t len)
+static int mcap_send_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
+ uint16_t mdl, uint8_t *data, size_t len)
{
mcap_rsp *cmd;
uint8_t *rsp;
@@ -427,7 +427,7 @@ static gboolean wait_response_timer(gpointer data)
return FALSE;
}
-void mcap_req_mdl_creation(struct mcap_mcl *mcl,
+void mcap_create_mdl(struct mcap_mcl *mcl,
uint8_t mdepid,
uint8_t conf,
mcap_mdl_operation_conf_cb connect_cb,
@@ -474,7 +474,7 @@ void mcap_req_mdl_creation(struct mcap_mcl *mcl,
mcl);
}
-void mcap_req_mdl_reconnect(struct mcap_mdl *mdl,
+void mcap_reconnect_mdl(struct mcap_mdl *mdl,
mcap_mdl_operation_cb reconnect_cb,
gpointer user_data,
GError **err)
@@ -529,7 +529,7 @@ static void send_delete_req(GError **err, struct mcap_mcl *mcl,
mcl);
}
-void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, mcap_mdl_notify_cb delete_cb,
+void mcap_delete_all_mdls(struct mcap_mcl *mcl, mcap_mdl_notify_cb delete_cb,
gpointer user_data, GError **err)
{
GSList *l;
@@ -559,7 +559,7 @@ void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, mcap_mdl_notify_cb delete_cb,
g_free(con);
}
-void mcap_req_mdl_deletion(struct mcap_mdl *mdl, mcap_mdl_notify_cb delete_cb,
+void mcap_delete_mdl(struct mcap_mdl *mdl, mcap_mdl_notify_cb delete_cb,
gpointer user_data, GError **err)
{
struct mcap_mcl *mcl= mdl->mcl;
@@ -915,7 +915,7 @@ void mcap_mcl_get_addr(struct mcap_mcl *mcl, bdaddr_t *addr)
bacpy(addr, &mcl->addr);
}
-static void mcap_delete_mdl(gpointer elem, gpointer user_data)
+static void mcap_del_mdl(gpointer elem, gpointer user_data)
{
struct mcap_mdl *mdl = elem;
gboolean notify = *(gboolean *)user_data;
@@ -1127,7 +1127,7 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdlid = ntohs(req->mdl);
if (mdlid == MCAP_ALL_MDLIDS) {
notify = FALSE;
- g_slist_foreach(mcl->mdls, mcap_delete_mdl, ¬ify);
+ g_slist_foreach(mcl->mdls, mcap_del_mdl, ¬ify);
g_slist_free(mcl->mdls);
mcl->mdls = NULL;
mcl->state = MCL_CONNECTED;
@@ -1158,7 +1158,7 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
update_mcl_state(mcl);
notify = TRUE;
- mcap_delete_mdl(mdl, ¬ify);
+ mcap_del_mdl(mdl, ¬ify);
resp:
mcap_send_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid,
@@ -1456,7 +1456,7 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
}
if (mdlid == MCAP_ALL_MDLIDS) {
- g_slist_foreach(mcl->mdls, mcap_delete_mdl, ¬ify);
+ g_slist_foreach(mcl->mdls, mcap_del_mdl, ¬ify);
g_slist_free(mcl->mdls);
mcl->mdls = NULL;
mcl->state = MCL_CONNECTED;
@@ -1465,7 +1465,7 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
update_mcl_state(mcl);
- mcap_delete_mdl(mdl, ¬ify);
+ mcap_del_mdl(mdl, ¬ify);
end:
deleted_cb(gerr, user_data);
return close;
@@ -1594,7 +1594,7 @@ static void mcap_connect_mdl_cb(GIOChannel *chan, GError *conn_err,
cb(mdl, conn_err, user_data);
}
-void mcap_mdl_connect(struct mcap_mdl *mdl, BtIOType BtType, uint16_t dcpsm,
+void mcap_connect_mdl(struct mcap_mdl *mdl, BtIOType BtType, uint16_t dcpsm,
mcap_mdl_operation_cb connect_cb, gpointer user_data, GError **err)
{
struct mcap_mdl_op_cb *con;
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index 7b8fcfd..fa62cbe 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -98,25 +98,25 @@ typedef void (* mcap_mcl_connect_cb) (struct mcap_mcl *mcl, GError *err,
/* Mdl operations*/
-void mcap_req_mdl_creation(struct mcap_mcl *mcl,
+void mcap_create_mdl(struct mcap_mcl *mcl,
uint8_t mdepid,
uint8_t conf,
mcap_mdl_operation_conf_cb connect_cb,
gpointer user_data,
GError **err);
-void mcap_req_mdl_reconnect(struct mcap_mdl *mdl,
+void mcap_reconnect_mdl(struct mcap_mdl *mdl,
mcap_mdl_operation_cb reconnect_cb,
gpointer user_data,
GError **err);
-void mcap_req_mdl_delete_all(struct mcap_mcl *mcl,
+void mcap_delete_all_mdls(struct mcap_mcl *mcl,
mcap_mdl_notify_cb delete_cb,
gpointer user_data,
GError **err);
-void mcap_req_mdl_deletion(struct mcap_mdl *mdl,
+void mcap_delete_mdl(struct mcap_mdl *mdl,
mcap_mdl_notify_cb delete_cb,
gpointer user_data,
GError **err);
-void mcap_mdl_connect(struct mcap_mdl *mdl,
+void mcap_connect_mdl(struct mcap_mdl *mdl,
BtIOType BtType,
uint16_t dcpsm,
mcap_mdl_operation_cb connect_cb,
--
1.6.3.3
^ permalink raw reply related
* [PATCH 58/60] Return a proper UNIX error instead of -1 in mcap_mdl_get_fd
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jose Antonio Santos Cadenas
In-Reply-To: <1279789097-2420-9-git-send-email-sancane@gmail.com>
From: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
---
mcap/mcap.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 30a8d56..b3017fb 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -29,6 +29,7 @@
#include <netinet/in.h>
#include <stdlib.h>
+#include <errno.h>
#include "mcap.h"
#include "mcap_lib.h"
@@ -640,7 +641,7 @@ static struct mcap_mcl *find_mcl(GSList *list, const bdaddr_t *addr)
int mcap_mdl_get_fd(struct mcap_mdl *mdl)
{
if ((!mdl) || (mdl->state != MDL_CONNECTED))
- return -1;
+ return -ENOTCONN;
return g_io_channel_unix_get_fd(mdl->dc);
}
--
1.6.3.3
^ permalink raw reply related
* [PATCH 57/60] Set Gerror at the end of the output paremeters list
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-8-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 34 +++++++++++++++++-----------------
mcap/mcap_lib.h | 49 ++++++++++++++++++++++++++++---------------------
2 files changed, 45 insertions(+), 38 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 869b6e7..30a8d56 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -429,9 +429,9 @@ static gboolean wait_response_timer(gpointer data)
void mcap_req_mdl_creation(struct mcap_mcl *mcl,
uint8_t mdepid,
uint8_t conf,
- GError **err,
mcap_mdl_operation_conf_cb connect_cb,
- gpointer user_data)
+ gpointer user_data,
+ GError **err)
{
struct mcap_mdl *mdl;
struct mcap_mdl_op_cb *con;
@@ -474,9 +474,9 @@ void mcap_req_mdl_creation(struct mcap_mcl *mcl,
}
void mcap_req_mdl_reconnect(struct mcap_mdl *mdl,
- GError **err,
mcap_mdl_operation_cb reconnect_cb,
- gpointer user_data)
+ gpointer user_data,
+ GError **err)
{
struct mcap_mdl_op_cb *con;
struct mcap_mcl *mcl = mdl->mcl;
@@ -528,8 +528,8 @@ static void send_delete_req(GError **err, struct mcap_mcl *mcl,
mcl);
}
-void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
- mcap_mdl_notify_cb delete_cb, gpointer user_data)
+void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, mcap_mdl_notify_cb delete_cb,
+ gpointer user_data, GError **err)
{
GSList *l;
struct mcap_mdl *mdl;
@@ -558,8 +558,8 @@ void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
g_free(con);
}
-void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_notify_cb delete_cb, gpointer user_data)
+void mcap_req_mdl_deletion(struct mcap_mdl *mdl, mcap_mdl_notify_cb delete_cb,
+ gpointer user_data, GError **err)
{
struct mcap_mcl *mcl= mdl->mcl;
struct mcap_mdl_op_cb *con;
@@ -590,8 +590,8 @@ void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
g_free(con);
}
-void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_notify_cb abort_cb, gpointer user_data)
+void mcap_mdl_abort(struct mcap_mdl *mdl, mcap_mdl_notify_cb abort_cb,
+ gpointer user_data, GError **err)
{
struct mcap_mdl_op_cb *con;
struct mcap_mcl *mcl = mdl->mcl;
@@ -892,8 +892,8 @@ static gboolean parse_set_opts(struct mcap_mdl_cb *mdl_cb, GError **err,
return TRUE;
}
-void mcap_mcl_set_cb(struct mcap_mcl *mcl, GError **gerr,
- gpointer user_data, McapMclCb cb1, ...)
+void mcap_mcl_set_cb(struct mcap_mcl *mcl, gpointer user_data, GError **gerr,
+ McapMclCb cb1, ...)
{
va_list args;
gboolean ret;
@@ -1594,7 +1594,7 @@ static void mcap_connect_mdl_cb(GIOChannel *chan, GError *conn_err,
}
void mcap_mdl_connect(struct mcap_mdl *mdl, BtIOType BtType, uint16_t dcpsm,
- GError **err, mcap_mdl_operation_cb connect_cb, gpointer user_data)
+ mcap_mdl_operation_cb connect_cb, gpointer user_data, GError **err)
{
struct mcap_mdl_op_cb *con;
@@ -1738,9 +1738,9 @@ static void connect_dc_event_cb(GIOChannel *chan, GError *err,
void mcap_create_mcl(struct mcap_instance *ms,
const bdaddr_t *addr,
uint16_t ccpsm,
- GError **err,
mcap_mcl_connect_cb connect_cb,
- gpointer user_data)
+ gpointer user_data,
+ GError **err)
{
struct mcap_mcl *mcl;
struct connect_mcl *con;
@@ -1917,12 +1917,12 @@ struct mcap_instance *mcap_create_instance(struct btd_adapter *btd_adapter,
BtIOSecLevel sec,
uint16_t ccpsm,
uint16_t dcpsm,
- GError **gerr,
mcap_mcl_event_cb mcl_connected,
mcap_mcl_event_cb mcl_reconnected,
mcap_mcl_event_cb mcl_disconnected,
mcap_mcl_event_cb mcl_uncached,
- gpointer user_data)
+ gpointer user_data,
+ GError **gerr)
{
struct mcap_instance *ms;
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index 54b40ad..7b8fcfd 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -101,24 +101,31 @@ typedef void (* mcap_mcl_connect_cb) (struct mcap_mcl *mcl, GError *err,
void mcap_req_mdl_creation(struct mcap_mcl *mcl,
uint8_t mdepid,
uint8_t conf,
- GError **err,
mcap_mdl_operation_conf_cb connect_cb,
- gpointer user_data);
-void mcap_req_mdl_reconnect(struct mcap_mdl *mdl, GError **err,
+ gpointer user_data,
+ GError **err);
+void mcap_req_mdl_reconnect(struct mcap_mdl *mdl,
mcap_mdl_operation_cb reconnect_cb,
- gpointer user_data);
-void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
- mcap_mdl_notify_cb delete_cb, gpointer user_data);
-void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_notify_cb delete_cb, gpointer user_data);
+ gpointer user_data,
+ GError **err);
+void mcap_req_mdl_delete_all(struct mcap_mcl *mcl,
+ mcap_mdl_notify_cb delete_cb,
+ gpointer user_data,
+ GError **err);
+void mcap_req_mdl_deletion(struct mcap_mdl *mdl,
+ mcap_mdl_notify_cb delete_cb,
+ gpointer user_data,
+ GError **err);
void mcap_mdl_connect(struct mcap_mdl *mdl,
- BtIOType BtType,
- uint16_t dcpsm,
- GError **err,
- mcap_mdl_operation_cb connect_cb,
- gpointer user_data);
-void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_notify_cb abort_cb, gpointer user_data);
+ BtIOType BtType,
+ uint16_t dcpsm,
+ mcap_mdl_operation_cb connect_cb,
+ gpointer user_data,
+ GError **err);
+void mcap_mdl_abort(struct mcap_mdl *mdl,
+ mcap_mdl_notify_cb abort_cb,
+ gpointer user_data,
+ GError **err);
int mcap_mdl_get_fd(struct mcap_mdl *mdl);
uint16_t mcap_mdl_get_mdlid(struct mcap_mdl *mdl);
@@ -128,12 +135,12 @@ uint16_t mcap_mdl_get_mdlid(struct mcap_mdl *mdl);
void mcap_create_mcl(struct mcap_instance *ms,
const bdaddr_t *addr,
uint16_t ccpsm,
- GError **err,
mcap_mcl_connect_cb connect_cb,
- gpointer user_data);
+ gpointer user_data,
+ GError **err);
void mcap_close_mcl(struct mcap_mcl *mcl, gboolean cache);
-void mcap_mcl_set_cb(struct mcap_mcl *mcl, GError **gerr,
- gpointer user_data, McapMclCb cb1, ...);
+void mcap_mcl_set_cb(struct mcap_mcl *mcl, gpointer user_data, GError **gerr,
+ McapMclCb cb1, ...);
void mcap_mcl_get_addr(struct mcap_mcl *mcl, bdaddr_t *addr);
struct mcap_mcl *mcap_mcl_ref(struct mcap_mcl *mcl);
@@ -144,12 +151,12 @@ void mcap_mcl_unref(struct mcap_mcl *mcl);
struct mcap_instance *mcap_create_instance(struct btd_adapter *btd_adapter,
BtIOSecLevel sec, uint16_t ccpsm,
uint16_t dcpsm,
- GError **gerr,
mcap_mcl_event_cb mcl_connected,
mcap_mcl_event_cb mcl_reconnected,
mcap_mcl_event_cb mcl_disconnected,
mcap_mcl_event_cb mcl_uncached,
- gpointer user_data);
+ gpointer user_data,
+ GError **gerr);
void mcap_release_instance(struct mcap_instance *ms);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 56/60] Use a generic function to send commands with variable parameters
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-7-git-send-email-sancane@gmail.com>
Future commands added to MCAP specification may use a variable
parameters greater than one Byte. This patch sets the fixed
part of a mcap response and append at the end of the command
the variable parameter depending of length provided.
---
mcap/mcap.c | 159 +++++++++++++++++++++++--------------------------
mcap/mcap.h | 14 +----
mcap/mcap_internal.h | 1 +
mcap/mcap_sync.c | 23 -------
4 files changed, 79 insertions(+), 118 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index a91f4b1..869b6e7 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -36,7 +36,6 @@
#define RESPONSE_TIMER 2 /* seconds */
#define MAX_CACHED 10 /* 10 devices */
-#define MIN_RSP_LEN 4 /* 4 Bytes */
#define MCAP_ERROR g_quark_from_static_string("mcap-error-quark")
@@ -307,46 +306,28 @@ int mcap_send_data(int sock, const uint8_t *buf, uint32_t size)
return 0;
}
-static int send4B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
- uint16_t mdl)
+static int mcap_send_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc, uint16_t mdl,
+ uint8_t *data, size_t len)
{
+ mcap_rsp *cmd;
uint8_t *rsp;
- mcap4B_rsp *rsp_err;
- int sent = -1;
+ int sock, sent;
+ if (mcl->cc == NULL)
+ return -1;
- rsp = g_malloc0(sizeof(mcap4B_rsp));
-
- rsp_err = (mcap4B_rsp *)rsp;
- rsp_err->op = oc;
- rsp_err->rc = rc;
- rsp_err->mdl = htons (mdl);
-
- if (mcl->cc)
- sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), rsp,
- sizeof(mcap4B_rsp));
- g_free(rsp);
- return sent;
-}
-
-static int send5B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
- uint16_t mdl, uint8_t param)
-{
- uint8_t *rsp;
- mcap5B_rsp *suc;
- int sent = -1;
+ sock = g_io_channel_unix_get_fd(mcl->cc);
- rsp = g_malloc0(sizeof(mcap5B_rsp));
+ rsp = g_malloc(sizeof(mcap_rsp) + len);
+ cmd = (mcap_rsp *)rsp;
+ cmd->op = oc;
+ cmd->rc = rc;
+ cmd->mdl = htons(mdl);
- suc = (mcap5B_rsp *)rsp;
- suc->op = oc;
- suc->rc = rc;
- suc->mdl = htons(mdl);
- suc->param = param;
+ if (data && (len > 0))
+ memcpy(rsp + sizeof(mcap_rsp), data, len);
- if (mcl->cc)
- sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), rsp,
- sizeof(mcap5B_rsp));
+ sent = mcap_send_data(sock, rsp, sizeof(mcap_rsp) + len);
g_free(rsp);
return sent;
}
@@ -371,7 +352,6 @@ static uint16_t generate_mdlid(struct mcap_mcl *mcl)
struct mcap_mdl *mdl;
do {
- DBG("Testing %d", mdlid);
mdl = get_mdl(mcl, mdlid);
if (!mdl) {
mcl->next_mdl = (mdlid % MCAP_MDLID_FINAL) + 1;
@@ -957,8 +937,10 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
uint8_t rsp;
if (len != sizeof(mcap_md_create_mdl_req)) {
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP,
- MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP,
+ MCAP_INVALID_PARAM_VALUE,
+ MCAP_MDLID_RESERVED,
+ NULL, 0);
return;
}
@@ -966,15 +948,15 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl_id = ntohs(req->mdl);
if ((mdl_id < MCAP_MDLID_INITIAL) || (mdl_id > MCAP_MDLID_FINAL)) {
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDL,
- mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDL,
+ mdl_id, NULL, 0);
return;
}
mdep_id = req->mdep;
if (mdep_id > MCAP_MDEPID_FINAL) {
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDEP,
- mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDEP,
+ mdl_id, NULL, 0);
return;
}
@@ -982,7 +964,8 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
if (mdl && (mdl->state == MDL_WAITING || mdl->state == MDL_DELETING )) {
/* Creation request arrives for a MDL that is being managed
* at current moment */
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_MDL_BUSY, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_MDL_BUSY,
+ mdl_id, NULL, 0);
return;
}
@@ -999,12 +982,13 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
/* Remote device set default configuration but upper profile */
/* has changed it. Protocol Error: force closing the MCL by */
/* remote device using UNSPECIFIED_ERROR response */
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_UNSPECIFIED_ERROR,
- mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP,
+ MCAP_UNSPECIFIED_ERROR, mdl_id, NULL, 0);
return;
}
if (rsp != MCAP_SUCCESS) {
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, rsp, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, rsp, mdl_id,
+ NULL, 0);
return;
}
@@ -1023,7 +1007,8 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl->state = MDL_WAITING;
mcl->state = MCL_PENDING;
- send5B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_SUCCESS, mdl_id, conf);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_SUCCESS, mdl_id,
+ &conf, 1);
}
static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
@@ -1035,8 +1020,10 @@ static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
uint8_t rsp;
if (len != sizeof(mcap_md_req)) {
- send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP,
- MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED);
+ mcap_send_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP,
+ MCAP_INVALID_PARAM_VALUE,
+ MCAP_MDLID_RESERVED,
+ NULL, 0);
return;
}
@@ -1045,14 +1032,14 @@ static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl = get_mdl(mcl, mdl_id);
if (!mdl) {
- send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP,
- MCAP_INVALID_MDL, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_INVALID_MDL,
+ mdl_id, NULL, 0);
return;
} else if (mdl->state == MDL_WAITING || mdl->state == MDL_DELETING ) {
/* Creation request arrives for a MDL that is being managed
* at current moment */
- send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_MDL_BUSY,
- mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_MDL_BUSY,
+ mdl_id, NULL, 0);
return;
}
@@ -1062,7 +1049,8 @@ static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
if (rsp != MCAP_SUCCESS) {
- send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, rsp, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, rsp, mdl_id,
+ NULL, 0);
return;
}
@@ -1071,7 +1059,8 @@ static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl->state = MDL_WAITING;
mcl->state = MCL_PENDING;
- send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_SUCCESS, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_SUCCESS, mdl_id,
+ NULL, 0);
}
static void process_md_abort_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
@@ -1083,8 +1072,8 @@ static void process_md_abort_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
uint16_t mdl_id;
if (len != sizeof(mcap_md_req)) {
- send4B_cmd(mcl, MCAP_MD_ABORT_MDL_RSP,
- MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED);
+ mcap_send_cmd(mcl, MCAP_MD_ABORT_MDL_RSP,
+ MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED, NULL, 0);
return;
}
@@ -1107,14 +1096,15 @@ static void process_md_abort_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
}
if (!abrt) {
- send4B_cmd(mcl, MCAP_MD_ABORT_MDL_RSP, MCAP_INVALID_MDL,
- mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_ABORT_MDL_RSP, MCAP_INVALID_MDL,
+ mdl_id, NULL, 0);
return;
}
mcl->cb->mdl_aborted(abrt, mcl->cb->user_data);
abrt->state = MDL_CLOSED;
- send4B_cmd(mcl, MCAP_MD_ABORT_MDL_RSP, MCAP_SUCCESS, mdl_id);
+ mcap_send_cmd(mcl, MCAP_MD_ABORT_MDL_RSP, MCAP_SUCCESS, mdl_id,
+ NULL, 0);
}
static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
@@ -1127,8 +1117,8 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
GSList *l;
if (len != sizeof(mcap_md_req)) {
- send4B_cmd(mcl, MCAP_MD_ABORT_MDL_RSP,
- MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED);
+ mcap_send_cmd(mcl, MCAP_MD_ABORT_MDL_RSP,
+ MCAP_INVALID_PARAM_VALUE, MCAP_MDLID_RESERVED, NULL, 0);
return;
}
@@ -1146,8 +1136,8 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
}
if ((mdlid < MCAP_MDLID_INITIAL) || (mdlid > MCAP_MDLID_FINAL)) {
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDL,
- mdlid);
+ mcap_send_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_INVALID_MDL,
+ mdlid, NULL, 0);
return;
}
@@ -1160,8 +1150,8 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
}
if (!mdl || (mdl->state == MDL_WAITING)) {
- send4B_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_INVALID_MDL,
- mdlid);
+ mcap_send_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_INVALID_MDL,
+ mdlid, NULL, 0);
return;
}
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
@@ -1170,7 +1160,8 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mcap_delete_mdl(mdl, ¬ify);
resp:
- send4B_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid);
+ mcap_send_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid,
+ NULL, 0);
}
static void invalid_req_state(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
@@ -1183,7 +1174,7 @@ static void invalid_req_state(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
* response if it is possible */
mdlr = len < sizeof(mcap_md_req) ? MCAP_MDLID_RESERVED :
ntohs(((mcap_md_req *)cmd)->mdl);
- send4B_cmd(mcl, cmd[0]+1, MCAP_INVALID_OPERATION, mdlr);
+ mcap_send_cmd(mcl, cmd[0]+1, MCAP_INVALID_OPERATION, mdlr, NULL, 0);
}
/* Function used to process commands depending of MCL state */
@@ -1237,7 +1228,7 @@ static gboolean check_err_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
gint err = MCAP_ERROR_FAILED;
gboolean close = FALSE;
uint16_t rmdl, smdl;
- mcap4B_rsp *rsp;
+ mcap_rsp *rsp;
char *msg;
if (cmd[0] == MCAP_ERROR_RSP) {
@@ -1247,7 +1238,7 @@ static gboolean check_err_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
}
/* Check if the response matches with the last request */
- if ((rlen < MIN_RSP_LEN) || ((mcl->lcmd[0] + 1) != cmd[0])) {
+ if ((rlen < sizeof(mcap_rsp)) || ((mcl->lcmd[0] + 1) != cmd[0])) {
msg = "Protocol error";
close = TRUE;
goto fail;
@@ -1259,7 +1250,7 @@ static gboolean check_err_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
goto fail;
}
- rsp = (mcap4B_rsp *)cmd;
+ rsp = (mcap_rsp *)cmd;
smdl = ntohs(cmdlast->mdl);
rmdl = ntohs(rsp->mdl);
if (rmdl != smdl) {
@@ -1304,12 +1295,12 @@ static gboolean process_md_create_mdl_rsp(struct mcap_mcl *mcl,
uint8_t conf = cmdlast->conf;
gboolean close = FALSE;
GError *gerr = NULL;
- mcap5B_rsp *rsp;
+ uint8_t *param;
g_free(mcl->priv_data);
mcl->priv_data = NULL;
- close = check_err_rsp(mcl, cmd, len, sizeof(mcap4B_rsp), &gerr);
+ close = check_err_rsp(mcl, cmd, len, sizeof(mcap_rsp) + 1, &gerr);
g_free(mcl->lcmd);
mcl->lcmd = NULL;
mcl->req = MCL_AVAILABLE;
@@ -1317,23 +1308,23 @@ static gboolean process_md_create_mdl_rsp(struct mcap_mcl *mcl,
if (gerr)
goto fail;
- if (len < sizeof(mcap5B_rsp)) {
+ if (len < sizeof(mcap_rsp)) {
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
"Protocol error");
close = TRUE;
goto fail;
}
- rsp = (mcap5B_rsp *)cmd;
+ param = cmd + sizeof(mcap_rsp);
/* Check if preferences changed */
- if ((conf != 0x00) && (rsp->param != conf)) {
+ if ((conf != 0x00) && (*param != conf)) {
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
"Configuration changed");
close = TRUE;
goto fail;
}
- connect_cb(mdl, rsp->param, gerr, user_data);
+ connect_cb(mdl, *param, gerr, user_data);
return close;
fail:
connect_cb(NULL, 0, gerr, user_data);
@@ -1351,14 +1342,14 @@ static gboolean process_md_reconnect_mdl_rsp(struct mcap_mcl *mcl,
mcap_mdl_operation_cb reconn_cb = reconn->cb.op;
gpointer user_data = reconn->user_data;
struct mcap_mdl *mdl = reconn->mdl;
- mcap4B_rsp *rsp = (mcap4B_rsp *)cmd;
+ mcap_rsp *rsp = (mcap_rsp *)cmd;
GError *gerr = NULL;
gboolean close = FALSE;
g_free(mcl->priv_data);
mcl->priv_data = NULL;
- close = check_err_rsp(mcl, cmd, len, sizeof(mcap4B_rsp), &gerr);
+ close = check_err_rsp(mcl, cmd, len, sizeof(mcap_rsp), &gerr);
g_free(mcl->lcmd);
mcl->lcmd = NULL;
@@ -1390,14 +1381,14 @@ static gboolean process_md_abort_mdl_rsp(struct mcap_mcl *mcl,
mcap_mdl_notify_cb abrt_cb = abrt->cb.notify;
gpointer user_data = abrt->user_data;
struct mcap_mdl *mdl = abrt->mdl;
- mcap4B_rsp *rsp = (mcap4B_rsp *)cmd;
+ mcap_rsp *rsp = (mcap_rsp *)cmd;
GError *gerr = NULL;
gboolean close = FALSE;
g_free(mcl->priv_data);
mcl->priv_data = NULL;
- close = check_err_rsp(mcl, cmd, len, sizeof(mcap4B_rsp), &gerr);
+ close = check_err_rsp(mcl, cmd, len, sizeof(mcap_rsp), &gerr);
g_free(mcl->lcmd);
mcl->lcmd = NULL;
@@ -1406,7 +1397,7 @@ static gboolean process_md_abort_mdl_rsp(struct mcap_mcl *mcl,
abrt_cb(gerr, user_data);
shutdown_mdl(mdl);
- if ((len >= MIN_RSP_LEN) && (rsp->rc == MCAP_INVALID_MDL)) {
+ if ((len >= sizeof(mcap_rsp)) && (rsp->rc == MCAP_INVALID_MDL)) {
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
g_free(mdl);
}
@@ -1447,7 +1438,7 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
g_free(mcl->priv_data);
mcl->priv_data = NULL;
- close = check_err_rsp(mcl, cmd, len, sizeof(mcap4B_rsp), &gerr);
+ close = check_err_rsp(mcl, cmd, len, sizeof(mcap_rsp), &gerr);
g_free(mcl->lcmd);
mcl->lcmd = NULL;
@@ -1517,8 +1508,8 @@ static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
(cmd[0] > MCAP_MD_DELETE_MDL_RSP &&
cmd[0] < MCAP_MD_SYNC_CAP_REQ)) {
error("Unknown cmd received (op code = %d)", cmd[0]);
- send4B_cmd(mcl, MCAP_ERROR_RSP, MCAP_INVALID_OP_CODE,
- MCAP_MDLID_RESERVED);
+ mcap_send_cmd(mcl, MCAP_ERROR_RSP, MCAP_INVALID_OP_CODE,
+ MCAP_MDLID_RESERVED, NULL, 0);
return;
}
diff --git a/mcap/mcap.h b/mcap/mcap.h
index 0299f42..9b95473 100644
--- a/mcap/mcap.h
+++ b/mcap/mcap.h
@@ -106,18 +106,10 @@ typedef struct {
*/
typedef struct {
- uint8_t op;
- uint8_t rc;
+ uint8_t op;
+ uint8_t rc;
uint16_t mdl;
-} __attribute__ ((packed)) mcap4B_rsp;
-
-typedef struct {
- uint8_t op;
- uint8_t rc;
- uint16_t mdl;
- uint8_t param;
-} __attribute__ ((packed)) mcap5B_rsp;
-
+} __attribute__ ((packed)) mcap_rsp;
/*
* MCAP Clock Synchronization Protocol
diff --git a/mcap/mcap_internal.h b/mcap/mcap_internal.h
index 9dacc12..7f16ab7 100644
--- a/mcap/mcap_internal.h
+++ b/mcap/mcap_internal.h
@@ -114,6 +114,7 @@ struct mcap_mdl {
};
int mcap_send_data(int sock, const uint8_t *buf, uint32_t size);
+
void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len);
#endif /* __MCAP_INTERNAL_H */
diff --git a/mcap/mcap_sync.c b/mcap/mcap_sync.c
index 76f1377..569a40a 100644
--- a/mcap/mcap_sync.c
+++ b/mcap/mcap_sync.c
@@ -33,27 +33,6 @@
#include "mcap_lib.h"
#include "mcap_internal.h"
-static int send_unsupported_req(struct mcap_mcl *mcl, uint8_t oc)
-{
- uint8_t *rsp;
- mcap4B_rsp *rsp_err;
- int sent;
-
-
- rsp = g_malloc0(sizeof(mcap4B_rsp));
-
- rsp_err = (mcap4B_rsp *)rsp;
- rsp_err->op = oc;
- rsp_err->rc = MCAP_REQUEST_NOT_SUPPORTED;
- rsp_err->mdl = htons (MCAP_MDLID_RESERVED);
-
- sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc),
- rsp,
- sizeof(mcap4B_rsp));
- g_free(rsp);
- return sent;
-}
-
void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
switch (cmd[0]) {
@@ -61,7 +40,6 @@ void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
DBG("TODO: received MCAP_MD_SYNC_CAP_REQ: %d",
MCAP_MD_SYNC_CAP_REQ);
/* Not implemented yet. Reply with unsupported request */
- send_unsupported_req(mcl, cmd[0]);
break;
case MCAP_MD_SYNC_CAP_RSP:
DBG("TODO: received MCAP_MD_SYNC_CAP_RSP: %d",
@@ -71,7 +49,6 @@ void proc_sync_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
DBG("TODO: received MCAP_MD_SYNC_SET_REQ: %d",
MCAP_MD_SYNC_SET_REQ);
/* Not implemented yet. Reply with unsupported request */
- send_unsupported_req(mcl, cmd[0]);
break;
case MCAP_MD_SYNC_SET_RSP:
DBG("TODO: received MCAP_MD_SYNC_SET_RSP: %d",
--
1.6.3.3
^ permalink raw reply related
* [PATCH 55/60] Change the get_addres function to match with other bluez functions
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-6-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 4 ++--
mcap/mcap_lib.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index e9d5d36..a91f4b1 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -929,9 +929,9 @@ void mcap_mcl_set_cb(struct mcap_mcl *mcl, GError **gerr,
return;
}
-bdaddr_t mcap_mcl_get_addr(struct mcap_mcl *mcl)
+void mcap_mcl_get_addr(struct mcap_mcl *mcl, bdaddr_t *addr)
{
- return mcl->addr;
+ bacpy(addr, &mcl->addr);
}
static void mcap_delete_mdl(gpointer elem, gpointer user_data)
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index 3d6e0b6..54b40ad 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -134,7 +134,7 @@ void mcap_create_mcl(struct mcap_instance *ms,
void mcap_close_mcl(struct mcap_mcl *mcl, gboolean cache);
void mcap_mcl_set_cb(struct mcap_mcl *mcl, GError **gerr,
gpointer user_data, McapMclCb cb1, ...);
-bdaddr_t mcap_mcl_get_addr(struct mcap_mcl *mcl);
+void mcap_mcl_get_addr(struct mcap_mcl *mcl, bdaddr_t *addr);
struct mcap_mcl *mcap_mcl_ref(struct mcap_mcl *mcl);
void mcap_mcl_unref(struct mcap_mcl *mcl);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 54/60] Set MDL state to closed when a connection failed
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-5-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 788b565..e9d5d36 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1823,6 +1823,7 @@ static void confirm_dc_event_cb(GIOChannel *chan, gpointer user_data)
if (!bt_io_accept(chan, connect_dc_event_cb, mdl, NULL,
&err)) {
error("MDL accept error %s", err->message);
+ mdl->state = MDL_CLOSED;
g_error_free(err);
goto drop;
}
--
1.6.3.3
^ permalink raw reply related
* [PATCH 53/60] Send error response when an unknown command is received.
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-4-git-send-email-sancane@gmail.com>
If an invalid Op Code is received (i.e. neither a Standard Op Code
nor a Clock Synchronization Protocol Op Code), we will send an reply
using an "Invalid Op Code" and the Op Code field to ERROR_RSP
---
mcap/mcap.c | 49 +++++++++++++++++++++++++------------------------
1 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 30e0827..788b565 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -934,27 +934,6 @@ bdaddr_t mcap_mcl_get_addr(struct mcap_mcl *mcl)
return mcl->addr;
}
-static void error_cmd_rsp(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
-{
- uint16_t mdlr;
-
- if (cmd[0] <= MCAP_MD_DELETE_MDL_RSP) {
- /* Standard Op Code request is invalid in current state */
- error("Invalid cmd received (op code = %d) in state %d",
- cmd[0], mcl->state);
- /* Get previously mdlid sent to generate an appropriate
- * response if it is possible */
- mdlr = len < sizeof(mcap_md_req) ? MCAP_MDLID_RESERVED :
- ntohs(((mcap_md_req *)cmd)->mdl);
- send4B_cmd(mcl, cmd[0]+1, MCAP_INVALID_OPERATION, mdlr);
- } else {
- error("Unknown cmd request received (op code = %d) in state %d",
- cmd[0], mcl->state);
- send4B_cmd(mcl, MCAP_ERROR_RSP, MCAP_INVALID_OP_CODE,
- MCAP_MDLID_RESERVED);
- }
-}
-
static void mcap_delete_mdl(gpointer elem, gpointer user_data)
{
struct mcap_mdl *mdl = elem;
@@ -1194,6 +1173,19 @@ resp:
send4B_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid);
}
+static void invalid_req_state(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
+{
+ uint16_t mdlr;
+
+ error("Invalid cmd received (op code = %d) in state %d", cmd[0],
+ mcl->state);
+ /* Get previously mdlid sent to generate an appropriate
+ * response if it is possible */
+ mdlr = len < sizeof(mcap_md_req) ? MCAP_MDLID_RESERVED :
+ ntohs(((mcap_md_req *)cmd)->mdl);
+ send4B_cmd(mcl, cmd[0]+1, MCAP_INVALID_OPERATION, mdlr);
+}
+
/* Function used to process commands depending of MCL state */
static void proc_req_connected(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
@@ -1208,7 +1200,7 @@ static void proc_req_connected(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
process_md_delete_mdl_req(mcl, cmd, len);
break;
default:
- error_cmd_rsp(mcl, cmd, len);
+ invalid_req_state(mcl, cmd, len);
}
}
@@ -1217,7 +1209,7 @@ static void proc_req_pending(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
if (cmd[0] == MCAP_MD_ABORT_MDL_REQ)
process_md_abort_mdl_req(mcl, cmd, len);
else
- error_cmd_rsp(mcl, cmd, len);
+ invalid_req_state(mcl, cmd, len);
}
static void proc_req_active(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
@@ -1233,7 +1225,7 @@ static void proc_req_active(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
process_md_delete_mdl_req(mcl, cmd, len);
break;
default:
- error_cmd_rsp(mcl, cmd, len);
+ invalid_req_state(mcl, cmd, len);
}
}
@@ -1521,6 +1513,15 @@ static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
GError *gerr = NULL;
+ if (cmd[0] > MCAP_MD_SYNC_INFO_IND ||
+ (cmd[0] > MCAP_MD_DELETE_MDL_RSP &&
+ cmd[0] < MCAP_MD_SYNC_CAP_REQ)) {
+ error("Unknown cmd received (op code = %d)", cmd[0]);
+ send4B_cmd(mcl, MCAP_ERROR_RSP, MCAP_INVALID_OP_CODE,
+ MCAP_MDLID_RESERVED);
+ return;
+ }
+
if ((cmd[0] >= MCAP_MD_SYNC_CAP_REQ) &&
(cmd[0] <= MCAP_MD_SYNC_INFO_IND)) {
proc_sync_cmd(mcl, cmd, len);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 52/60] Avoid double insertion of the same MDL in an MCL
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-3-git-send-email-sancane@gmail.com>
We don't have to insert an MDL in the list when we receive a
request to create a new data channel using a mdlid that it is
already created.
---
mcap/mcap.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 1e55bc7..30e0827 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1033,6 +1033,7 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl = g_malloc0(sizeof(struct mcap_mdl));
mdl->mcl = mcl;
mdl->mdlid = mdl_id;
+ mcl->mdls = g_slist_insert_sorted(mcl->mdls, mdl, compare_mdl);
} else if (mdl->state == MDL_CONNECTED) {
/* MCAP specification says that we should close the MCL if
* it is open when we receive a MD_CREATE_MDL_REQ */
@@ -1041,7 +1042,6 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mdl->mdep_id = mdep_id;
mdl->state = MDL_WAITING;
- mcl->mdls = g_slist_insert_sorted(mcl->mdls, mdl, compare_mdl);
mcl->state = MCL_PENDING;
send5B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_SUCCESS, mdl_id, conf);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 51/60] Change name for callback used to report status of delete and abort operations
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-2-git-send-email-sancane@gmail.com>
---
mcap/mcap.c | 22 +++++++++++-----------
mcap/mcap_lib.h | 8 ++++----
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index e89b720..1e55bc7 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -54,7 +54,7 @@ struct connect_mcl {
typedef union {
mcap_mdl_operation_cb op;
mcap_mdl_operation_conf_cb op_conf;
- mcap_mdl_del_cb del;
+ mcap_mdl_notify_cb notify;
} mcap_cb_type;
struct mcap_mdl_op_cb {
@@ -266,7 +266,7 @@ static void mcap_notify_error(struct mcap_mcl *mcl, GError *err)
l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
shutdown_mdl(l->data);
update_mcl_state(mcl);
- con->cb.del(err, con->user_data);
+ con->cb.notify(err, con->user_data);
break;
case MCAP_MD_DELETE_MDL_REQ:
for (l = mcl->mdls; l; l = l->next) {
@@ -276,7 +276,7 @@ static void mcap_notify_error(struct mcap_mcl *mcl, GError *err)
MDL_CLOSED;
}
update_mcl_state(mcl);
- con->cb.del(err, con->user_data);
+ con->cb.notify(err, con->user_data);
break;
case MCAP_MD_RECONNECT_MDL_REQ:
st = MDL_WAITING;
@@ -549,7 +549,7 @@ static void send_delete_req(GError **err, struct mcap_mcl *mcl,
}
void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
- mcap_mdl_del_cb delete_cb, gpointer user_data)
+ mcap_mdl_notify_cb delete_cb, gpointer user_data)
{
GSList *l;
struct mcap_mdl *mdl;
@@ -570,7 +570,7 @@ void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
con = g_new0(struct mcap_mdl_op_cb, 1);
con->mdl = NULL;
- con->cb.del = delete_cb;
+ con->cb.notify = delete_cb;
con->user_data = user_data;
send_delete_req(err, mcl, con, MCAP_ALL_MDLIDS);
@@ -579,7 +579,7 @@ void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
}
void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_del_cb delete_cb, gpointer user_data)
+ mcap_mdl_notify_cb delete_cb, gpointer user_data)
{
struct mcap_mcl *mcl= mdl->mcl;
struct mcap_mdl_op_cb *con;
@@ -602,7 +602,7 @@ void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
con = g_new0(struct mcap_mdl_op_cb, 1);
con->mdl = mdl;
- con->cb.del = delete_cb;
+ con->cb.notify = delete_cb;
con->user_data = user_data;
send_delete_req(err, mcl, con, mdl->mdlid);
@@ -611,7 +611,7 @@ void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
}
void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_del_cb abort_cb, gpointer user_data)
+ mcap_mdl_notify_cb abort_cb, gpointer user_data)
{
struct mcap_mdl_op_cb *con;
struct mcap_mcl *mcl = mdl->mcl;
@@ -633,7 +633,7 @@ void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
}
con->mdl = mdl;
- con->cb.del = abort_cb;
+ con->cb.notify = abort_cb;
con->user_data = user_data;
mcl->priv_data = con;
@@ -1395,7 +1395,7 @@ static gboolean process_md_abort_mdl_rsp(struct mcap_mcl *mcl,
uint8_t *cmd, uint32_t len)
{
struct mcap_mdl_op_cb *abrt = mcl->priv_data;
- mcap_mdl_del_cb abrt_cb = abrt->cb.del;
+ mcap_mdl_notify_cb abrt_cb = abrt->cb.notify;
gpointer user_data = abrt->user_data;
struct mcap_mdl *mdl = abrt->mdl;
mcap4B_rsp *rsp = (mcap4B_rsp *)cmd;
@@ -1444,7 +1444,7 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
{
struct mcap_mdl_op_cb *del = mcl->priv_data;
struct mcap_mdl *mdl = del->mdl;
- mcap_mdl_del_cb deleted_cb = del->cb.del;
+ mcap_mdl_notify_cb deleted_cb = del->cb.notify;
gpointer user_data = del->user_data;
mcap_md_req *cmdlast = (mcap_md_req *) mcl->lcmd;
uint16_t mdlid = ntohs(cmdlast->mdl);
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index afac8aa..3d6e0b6 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -79,7 +79,7 @@ typedef void (* mcap_mdl_operation_conf_cb) (struct mcap_mdl *mdl, uint8_t conf,
GError *err, gpointer data);
typedef void (* mcap_mdl_operation_cb) (struct mcap_mdl *mdl, GError *err,
gpointer data);
-typedef void (* mcap_mdl_del_cb) (GError *err, gpointer data);
+typedef void (* mcap_mdl_notify_cb) (GError *err, gpointer data);
/* Next function should return an MCAP appropriate response code */
typedef uint8_t (* mcap_remote_mdl_conn_req_cb) (struct mcap_mcl *mcl,
@@ -108,9 +108,9 @@ void mcap_req_mdl_reconnect(struct mcap_mdl *mdl, GError **err,
mcap_mdl_operation_cb reconnect_cb,
gpointer user_data);
void mcap_req_mdl_delete_all(struct mcap_mcl *mcl, GError **err,
- mcap_mdl_del_cb delete_cb, gpointer user_data);
+ mcap_mdl_notify_cb delete_cb, gpointer user_data);
void mcap_req_mdl_deletion(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_del_cb delete_cb, gpointer user_data);
+ mcap_mdl_notify_cb delete_cb, gpointer user_data);
void mcap_mdl_connect(struct mcap_mdl *mdl,
BtIOType BtType,
uint16_t dcpsm,
@@ -118,7 +118,7 @@ void mcap_mdl_connect(struct mcap_mdl *mdl,
mcap_mdl_operation_cb connect_cb,
gpointer user_data);
void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
- mcap_mdl_del_cb abort_cb, gpointer user_data);
+ mcap_mdl_notify_cb abort_cb, gpointer user_data);
int mcap_mdl_get_fd(struct mcap_mdl *mdl);
uint16_t mcap_mdl_get_mdlid(struct mcap_mdl *mdl);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 50/60] Check control channel before calling to g_io_channel_unix_get_fd
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789097-2420-1-git-send-email-sancane@gmail.com>
Glib does not return file descriptor -1 when a NULL pointer is passed
as parameter in g_io_channel_unix_get_fd function. Pointer parameter
is deferrence in glib without checking NULL
---
mcap/mcap.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index e8a93a1..e89b720 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -312,7 +312,7 @@ static int send4B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
{
uint8_t *rsp;
mcap4B_rsp *rsp_err;
- int sent;
+ int sent = -1;
rsp = g_malloc0(sizeof(mcap4B_rsp));
@@ -322,9 +322,9 @@ static int send4B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
rsp_err->rc = rc;
rsp_err->mdl = htons (mdl);
- sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc),
- rsp,
- sizeof(mcap4B_rsp));
+ if (mcl->cc)
+ sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), rsp,
+ sizeof(mcap4B_rsp));
g_free(rsp);
return sent;
}
@@ -334,7 +334,7 @@ static int send5B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
{
uint8_t *rsp;
mcap5B_rsp *suc;
- int sent;
+ int sent = -1;
rsp = g_malloc0(sizeof(mcap5B_rsp));
@@ -344,7 +344,8 @@ static int send5B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
suc->mdl = htons(mdl);
suc->param = param;
- sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), rsp,
+ if (mcl->cc)
+ sent = mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), rsp,
sizeof(mcap5B_rsp));
g_free(rsp);
return sent;
@@ -962,6 +963,7 @@ static void mcap_delete_mdl(gpointer elem, gpointer user_data)
shutdown_mdl(mdl);
if (notify)
mdl->mcl->cb->mdl_deleted(mdl, mdl->mcl->cb->user_data);
+
g_free(mdl);
}
@@ -1187,6 +1189,7 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
update_mcl_state(mcl);
notify = TRUE;
mcap_delete_mdl(mdl, ¬ify);
+
resp:
send4B_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid);
}
--
1.6.3.3
^ permalink raw reply related
* [PATCH 49/60] Restore state in MCL whenever an error takes place.
From: Santiago Carot-Nemesio @ 2010-07-22 8:58 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1279789001-4587-30-git-send-email-santoscadenas@gmail.com>
---
mcap/mcap.c | 55 +++++++++++++++++++++++--------------------------------
1 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 434d50f..e8a93a1 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -241,8 +241,7 @@ static gint cmp_mdl_state(gconstpointer a, gconstpointer b)
return 1;
}
-static void mcap_notify_error(struct mcap_mcl *mcl, GError *err,
- gboolean restore)
+static void mcap_notify_error(struct mcap_mcl *mcl, GError *err)
{
struct mcap_mdl_op_cb *con = mcl->priv_data;
struct mcap_mdl *mdl;
@@ -254,44 +253,36 @@ static void mcap_notify_error(struct mcap_mcl *mcl, GError *err,
switch (mcl->lcmd[0]){
case MCAP_MD_CREATE_MDL_REQ:
- if (restore) {
- st = MDL_WAITING;
- l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
- mdl = l->data;
- mcl->mdls = g_slist_remove(mcl->mdls, mdl);
- g_free(mdl);
- update_mcl_state(mcl);
- }
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ mdl = l->data;
+ mcl->mdls = g_slist_remove(mcl->mdls, mdl);
+ g_free(mdl);
+ update_mcl_state(mcl);
con->cb.op_conf(NULL, 0, err, con->user_data);
break;
case MCAP_MD_ABORT_MDL_REQ:
- if (restore) {
- st = MDL_WAITING;
- l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
- shutdown_mdl(l->data);
- update_mcl_state(mcl);
- }
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ shutdown_mdl(l->data);
+ update_mcl_state(mcl);
con->cb.del(err, con->user_data);
break;
case MCAP_MD_DELETE_MDL_REQ:
- if (restore) {
- for (l = mcl->mdls; l; l = l->next) {
- mdl = l->data;
- if (mdl->state == MDL_DELETING)
- mdl->state = (mdl->dc) ? MDL_CONNECTED :
+ for (l = mcl->mdls; l; l = l->next) {
+ mdl = l->data;
+ if (mdl->state == MDL_DELETING)
+ mdl->state = (mdl->dc) ? MDL_CONNECTED :
MDL_CLOSED;
- }
- update_mcl_state(mcl);
}
+ update_mcl_state(mcl);
con->cb.del(err, con->user_data);
break;
case MCAP_MD_RECONNECT_MDL_REQ:
- if (restore) {
- st = MDL_WAITING;
- l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
- shutdown_mdl(l->data);
- update_mcl_state(mcl);
- }
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ shutdown_mdl(l->data);
+ update_mcl_state(mcl);
con->cb.op(NULL, err, con->user_data);
break;
}
@@ -446,7 +437,7 @@ static gboolean wait_response_timer(gpointer data)
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
"Timeout waiting response");
- mcap_notify_error(mcl, gerr, FALSE);
+ mcap_notify_error(mcl, gerr);
g_error_free(gerr);
mcl->ms->mcl_disconnected_cb(mcl, mcl->ms->user_data);
@@ -1551,7 +1542,7 @@ static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
mcl->req = MCL_AVAILABLE;
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_REQ_IGNORED,
"Initiator sent a request with more priority");
- mcap_notify_error(mcl, gerr, TRUE);
+ mcap_notify_error(mcl, gerr);
return;
}
proc_response(mcl, cmd, len);
@@ -1665,7 +1656,7 @@ fail:
/* notify error in pending callback */
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_MCL_CLOSED,
"MCL closed");
- mcap_notify_error(mcl, gerr, TRUE);
+ mcap_notify_error(mcl, gerr);
g_error_free(gerr);
}
mcl->ms->mcl_disconnected_cb(mcl, mcl->ms->user_data);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 48/60] Notify MCL closed when there is a pending callback
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-29-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
---
mcap/mcap.c | 11 ++++++++++-
mcap/mcap_lib.h | 1 +
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index f164e76..434d50f 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1643,6 +1643,7 @@ void mcap_mdl_connect(struct mcap_mdl *mdl, BtIOType BtType, uint16_t dcpsm,
static gboolean mcl_control_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
+ GError *gerr = NULL;
struct mcap_mcl *mcl = data;
int sk, len;
@@ -1659,8 +1660,16 @@ static gboolean mcl_control_cb(GIOChannel *chan, GIOCondition cond,
proc_cmd(mcl, buf, (uint32_t)len);
return TRUE;
fail:
- if (mcl->state != MCL_IDLE)
+ if (mcl->state != MCL_IDLE) {
+ if (mcl->req == MCL_WAITING_RSP) {
+ /* notify error in pending callback */
+ g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_MCL_CLOSED,
+ "MCL closed");
+ mcap_notify_error(mcl, gerr, TRUE);
+ g_error_free(gerr);
+ }
mcl->ms->mcl_disconnected_cb(mcl, mcl->ms->user_data);
+ }
mcap_cache_mcl(mcl);
return FALSE;
}
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index 67c2f29..afac8aa 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -52,6 +52,7 @@ typedef enum {
MCAP_ERROR_INVALID_ARGS,
MCAP_ERROR_ALREADY_EXISTS,
MCAP_ERROR_REQ_IGNORED,
+ MCAP_ERROR_MCL_CLOSED,
MCAP_ERROR_FAILED
} McapError;
--
1.6.3.3
^ permalink raw reply related
* [PATCH 47/60] Random generation of first mdlid used as based to create data channels
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-28-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3280 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
Add random mdlid generation to avoid mdlid collisions when
two instances create a data channel at the same time.
---
mcap/mcap.c | 53 ++++++++++++++++++++++++++-----------------------
mcap/mcap_internal.h | 1 +
2 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 3f3268b..f164e76 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -28,6 +28,7 @@
#include "error.h"
#include <netinet/in.h>
+#include <stdlib.h>
#include "mcap.h"
#include "mcap_lib.h"
@@ -358,24 +359,37 @@ static int send5B_cmd(struct mcap_mcl *mcl, uint8_t oc, uint8_t rc,
return sent;
}
-static uint16_t generate_mdlid(struct mcap_mcl *mcl)
+static struct mcap_mdl *get_mdl(struct mcap_mcl *mcl, uint16_t mdlid)
{
- uint16_t mdlid = MCAP_MDLID_INITIAL;
- struct mcap_mdl *mdl;
GSList *l;
+ struct mcap_mdl *mdl;
for (l = mcl->mdls; l; l = l->next) {
mdl = l->data;
- if (mdlid < mdl->mdlid)
- break;
- else
- mdlid = mdl->mdlid + 1;
+ if (mdlid == mdl->mdlid)
+ return mdl;
}
- if (mdlid > MCAP_MDLID_FINAL)
- return 0;
+ return NULL;
+}
+
+static uint16_t generate_mdlid(struct mcap_mcl *mcl)
+{
+ uint16_t mdlid = mcl->next_mdl;
+ struct mcap_mdl *mdl;
- return mdlid;
+ do {
+ DBG("Testing %d", mdlid);
+ mdl = get_mdl(mcl, mdlid);
+ if (!mdl) {
+ mcl->next_mdl = (mdlid % MCAP_MDLID_FINAL) + 1;
+ return mdlid;
+ } else
+ mdlid = (mdlid % MCAP_MDLID_FINAL) + 1;
+ } while (mdlid != mcl->next_mdl);
+
+ /* No more mdlids availables */
+ return 0;
}
static uint8_t *create_req(uint8_t op, uint16_t mdl_id)
@@ -949,20 +963,6 @@ static void error_cmd_rsp(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
}
}
-static struct mcap_mdl *get_mdl(struct mcap_mcl *mcl, uint16_t mdlid)
-{
- GSList *l;
- struct mcap_mdl *mdl;
-
- for (l = mcl->mdls; l; l = l->next) {
- mdl = l->data;
- if (mdlid == mdl->mdlid)
- return mdl;
- }
-
- return NULL;
-}
-
static void mcap_delete_mdl(gpointer elem, gpointer user_data)
{
struct mcap_mdl *mdl = elem;
@@ -1764,6 +1764,7 @@ void mcap_create_mcl(struct mcap_instance *ms,
mcl->state = MCL_IDLE;
bacpy(&mcl->addr, addr);
set_default_cb(mcl);
+ mcl->next_mdl = (rand() % MCAP_MDLID_FINAL) + 1;
mcl = mcap_mcl_ref(mcl);
} else
mcl->ctrl |= MCAP_CTRL_CONN;
@@ -1899,6 +1900,7 @@ static void confirm_mcl_event_cb(GIOChannel *chan, gpointer user_data)
mcl->ms = ms;
bacpy(&mcl->addr, &dst);
set_default_cb(mcl);
+ mcl->next_mdl = (rand() % MCAP_MDLID_FINAL) + 1;
mcl = mcap_mcl_ref(mcl);
}
@@ -1983,7 +1985,8 @@ struct mcap_instance *mcap_create_instance(struct btd_adapter *btd_adapter,
g_free(ms);
return NULL;
}
-
+ /* Initialize random seed to generate mdlids for this instance */
+ srand(time(NULL));
return ms;
}
diff --git a/mcap/mcap_internal.h b/mcap/mcap_internal.h
index 3aaeed5..9dacc12 100644
--- a/mcap/mcap_internal.h
+++ b/mcap/mcap_internal.h
@@ -94,6 +94,7 @@ struct mcap_mcl {
uint8_t *lcmd; /* Last command sent */
guint ref; /* References counter */
uint8_t ctrl; /* MCL control flag */
+ uint16_t next_mdl; /* id used to create next MDL */
};
#define MCAP_CTRL_CACHED 0x01 /* MCL is cached */
--
1.6.3.3
^ permalink raw reply related
* [PATCH 46/60] Process received command in base to previous request sent
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-27-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1021 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
---
mcap/mcap.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 18220bc..3f3268b 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1254,6 +1254,12 @@ static gboolean check_err_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
mcap4B_rsp *rsp;
char *msg;
+ if (cmd[0] == MCAP_ERROR_RSP) {
+ msg = "MCAP_ERROR_RSP received";
+ close = TRUE;
+ goto fail;
+ }
+
/* Check if the response matches with the last request */
if ((rlen < MIN_RSP_LEN) || ((mcl->lcmd[0] + 1) != cmd[0])) {
msg = "Protocol error";
@@ -1492,11 +1498,7 @@ static void proc_response(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
gboolean close;
RELEASE_TIMER(mcl);
- switch (cmd[0]) {
- case MCAP_ERROR_RSP:
- error("MCAP_ERROR_RSP received");
- close = TRUE;
- break;
+ switch (mcl->lcmd[0] + 1) {
case MCAP_MD_CREATE_MDL_RSP:
close = process_md_create_mdl_rsp(mcl, cmd, len);
break;
--
1.6.3.3
^ permalink raw reply related
* [PATCH 45/60] Fix double reconnection problem using the same mdlid
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-26-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 744 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
---
mcap/mcap.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index a2cfa8c..18220bc 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -1076,6 +1076,12 @@ static void process_md_reconnect_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP,
MCAP_INVALID_MDL, mdl_id);
return;
+ } else if (mdl->state == MDL_WAITING || mdl->state == MDL_DELETING ) {
+ /* Creation request arrives for a MDL that is being managed
+ * at current moment */
+ send4B_cmd(mcl, MCAP_MD_RECONNECT_MDL_RSP, MCAP_MDL_BUSY,
+ mdl_id);
+ return;
}
/* Callback to upper layer */
--
1.6.3.3
^ permalink raw reply related
* [PATCH 44/60] Restore state after INITIATOR ignore a request
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-25-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6423 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
When ACEPTOR receives a request when an outstanding request is
pending it should reply to the INITIATOR and restore previous state
if it is needed.
---
mcap/mcap.c | 140 ++++++++++++++++++++++++++++++++++++++++--------------
mcap/mcap_lib.h | 1 +
2 files changed, 104 insertions(+), 37 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 7bea1ad..a2cfa8c 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -194,28 +194,112 @@ static void mcap_send_std_opcode(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->req = MCL_WAITING_RSP;
}
-static void mcap_notify_error(struct mcap_mcl *mcl, GError *err)
+static void update_mcl_state(struct mcap_mcl *mcl)
+{
+ GSList *l;
+ struct mcap_mdl *mdl;
+
+ if (mcl->state == MCL_PENDING)
+ return;
+
+ for (l = mcl->mdls; l; l = l->next) {
+ mdl = l->data;
+
+ if (mdl->state == MDL_CONNECTED) {
+ mcl->state = MCL_ACTIVE;
+ return;
+ }
+ }
+
+ mcl->state = MCL_CONNECTED;
+}
+
+static void shutdown_mdl(struct mcap_mdl *mdl)
+{
+ mdl->state = MDL_CLOSED;
+
+ g_source_remove(mdl->wid);
+
+ if (mdl->dc) {
+ g_io_channel_shutdown(mdl->dc, TRUE, NULL);
+ g_io_channel_unref(mdl->dc);
+ mdl->dc = NULL;
+ }
+}
+
+static gint cmp_mdl_state(gconstpointer a, gconstpointer b)
+{
+ const struct mcap_mdl *mdl = a;
+ const MDLState *st = b;
+
+ if (mdl->state == *st)
+ return 0;
+ else if (mdl->state < *st)
+ return -1;
+ else
+ return 1;
+}
+
+static void mcap_notify_error(struct mcap_mcl *mcl, GError *err,
+ gboolean restore)
{
struct mcap_mdl_op_cb *con = mcl->priv_data;
+ struct mcap_mdl *mdl;
+ MDLState st;
+ GSList *l;
if (!con || !mcl->lcmd)
return;
switch (mcl->lcmd[0]){
case MCAP_MD_CREATE_MDL_REQ:
+ if (restore) {
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ mdl = l->data;
+ mcl->mdls = g_slist_remove(mcl->mdls, mdl);
+ g_free(mdl);
+ update_mcl_state(mcl);
+ }
con->cb.op_conf(NULL, 0, err, con->user_data);
break;
case MCAP_MD_ABORT_MDL_REQ:
+ if (restore) {
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ shutdown_mdl(l->data);
+ update_mcl_state(mcl);
+ }
+ con->cb.del(err, con->user_data);
+ break;
case MCAP_MD_DELETE_MDL_REQ:
+ if (restore) {
+ for (l = mcl->mdls; l; l = l->next) {
+ mdl = l->data;
+ if (mdl->state == MDL_DELETING)
+ mdl->state = (mdl->dc) ? MDL_CONNECTED :
+ MDL_CLOSED;
+ }
+ update_mcl_state(mcl);
+ }
con->cb.del(err, con->user_data);
break;
case MCAP_MD_RECONNECT_MDL_REQ:
+ if (restore) {
+ st = MDL_WAITING;
+ l = g_slist_find_custom(mcl->mdls, &st, cmp_mdl_state);
+ shutdown_mdl(l->data);
+ update_mcl_state(mcl);
+ }
con->cb.op(NULL, err, con->user_data);
break;
}
g_free(mcl->priv_data);
mcl->priv_data = NULL;
+
+ g_free(mcl->lcmd);
+ mcl->lcmd = NULL;
}
int mcap_send_data(int sock, const uint8_t *buf, uint32_t size)
@@ -348,7 +432,7 @@ static gboolean wait_response_timer(gpointer data)
g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_FAILED,
"Timeout waiting response");
- mcap_notify_error(mcl, gerr);
+ mcap_notify_error(mcl, gerr, FALSE);
g_error_free(gerr);
mcl->ms->mcl_disconnected_cb(mcl, mcl->ms->user_data);
@@ -552,26 +636,6 @@ void mcap_mdl_abort(struct mcap_mdl *mdl, GError **err,
mcl);
}
-static void update_mcl_state(struct mcap_mcl *mcl)
-{
- GSList *l;
- struct mcap_mdl *mdl;
-
- if (mcl->state == MCL_PENDING)
- return;
-
- for (l = mcl->mdls; l; l = l->next) {
- mdl = l->data;
-
- if (mdl->state == MDL_CONNECTED) {
- mcl->state = MCL_ACTIVE;
- return;
- }
- }
-
- mcl->state = MCL_CONNECTED;
-}
-
static struct mcap_mcl *find_mcl(GSList *list, const bdaddr_t *addr)
{
GSList *l;
@@ -603,19 +667,6 @@ uint16_t mcap_mdl_get_mdlid(struct mcap_mdl *mdl)
return mdl->mdlid;
}
-static void shutdown_mdl(struct mcap_mdl *mdl)
-{
- mdl->state = MDL_CLOSED;
-
- g_source_remove(mdl->wid);
-
- if (mdl->dc) {
- g_io_channel_shutdown(mdl->dc, TRUE, NULL);
- g_io_channel_unref(mdl->dc);
- mdl->dc = NULL;
- }
-}
-
static void mcap_free_mdls(struct mcap_mcl *mcl, gboolean save)
{
GSList *l;
@@ -955,6 +1006,14 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
+ mdl = get_mdl(mcl, mdl_id);
+ if (mdl && (mdl->state == MDL_WAITING || mdl->state == MDL_DELETING )) {
+ /* Creation request arrives for a MDL that is being managed
+ * at current moment */
+ send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_MDL_BUSY, mdl_id);
+ return;
+ }
+
cfga = conf = req->conf;
/* Callback to upper layer */
rsp = mcl->cb->mdl_conn_req(mcl, mdep_id, mdl_id, &conf,
@@ -977,7 +1036,6 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
- mdl = get_mdl(mcl, mdl_id);
if (!mdl) {
mdl = g_malloc0(sizeof(struct mcap_mdl));
mdl->mcl = mcl;
@@ -987,6 +1045,7 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
* it is open when we receive a MD_CREATE_MDL_REQ */
shutdown_mdl(mdl);
}
+
mdl->mdep_id = mdep_id;
mdl->state = MDL_WAITING;
mcl->mdls = g_slist_insert_sorted(mcl->mdls, mdl, compare_mdl);
@@ -1458,6 +1517,8 @@ static void proc_response(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
+ GError *gerr = NULL;
+
if ((cmd[0] >= MCAP_MD_SYNC_CAP_REQ) &&
(cmd[0] <= MCAP_MD_SYNC_INFO_IND)) {
proc_sync_cmd(mcl, cmd, len);
@@ -1476,8 +1537,13 @@ static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
if (mcl->role == MCL_INITIATOR)
/* ignore */
return;
- proc_req[mcl->state](mcl, cmd, len);
/* Initiator will ignore our last request */
+ proc_req[mcl->state](mcl, cmd, len);
+ RELEASE_TIMER(mcl);
+ mcl->req = MCL_AVAILABLE;
+ g_set_error(&gerr, MCAP_ERROR, MCAP_ERROR_REQ_IGNORED,
+ "Initiator sent a request with more priority");
+ mcap_notify_error(mcl, gerr, TRUE);
return;
}
proc_response(mcl, cmd, len);
diff --git a/mcap/mcap_lib.h b/mcap/mcap_lib.h
index 2283dac..67c2f29 100644
--- a/mcap/mcap_lib.h
+++ b/mcap/mcap_lib.h
@@ -51,6 +51,7 @@ typedef enum {
/* MCAP Internal Errors */
MCAP_ERROR_INVALID_ARGS,
MCAP_ERROR_ALREADY_EXISTS,
+ MCAP_ERROR_REQ_IGNORED,
MCAP_ERROR_FAILED
} McapError;
--
1.6.3.3
^ permalink raw reply related
* [PATCH 43/60] Acceptor should not resend commands
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: José Antonio Santos-Cadenas
In-Reply-To: <1279789001-4587-24-git-send-email-santoscadenas@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4337 bytes --]
From: José Antonio Santos-Cadenas <santoscadenas@gmail.com>
Acceptor of the MCL should not send the last commands sent when there
is an outstanding request.
---
mcap/mcap.c | 72 +++++++++--------------------------------------------------
1 files changed, 11 insertions(+), 61 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index ff6766d..7bea1ad 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -955,16 +955,8 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
- mdl = get_mdl(mcl, mdl_id);
- if (mdl && mdl->state == MDL_WAITING) {
- /* A remote petition is also triying to connect this mdl_id
- * so the petition is rejected by the moment */
- send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_MDL_BUSY, mdl_id);
- return;
- }
-
- /* Callback to upper layer */
cfga = conf = req->conf;
+ /* Callback to upper layer */
rsp = mcl->cb->mdl_conn_req(mcl, mdep_id, mdl_id, &conf,
mcl->cb->user_data);
if (mcl->state == MCL_IDLE) {
@@ -985,6 +977,7 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
+ mdl = get_mdl(mcl, mdl_id);
if (!mdl) {
mdl = g_malloc0(sizeof(struct mcap_mdl));
mdl->mcl = mcl;
@@ -1137,12 +1130,7 @@ static void process_md_delete_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
update_mcl_state(mcl);
notify = TRUE;
- if (mdl->state == MDL_DELETING) {
- /* Remote deviced requests deleting an MDL that upper profile
- * is trying to delete, MDL will be freed when reply arrives. */
- mdl->mcl->cb->mdl_deleted(mdl, mdl->mcl->cb->user_data);
- } else
- mcap_delete_mdl(mdl, ¬ify);
+ mcap_delete_mdl(mdl, ¬ify);
resp:
send4B_cmd(mcl, MCAP_MD_DELETE_MDL_RSP, MCAP_SUCCESS, mdlid);
}
@@ -1395,7 +1383,6 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
gpointer user_data = del->user_data;
mcap_md_req *cmdlast = (mcap_md_req *) mcl->lcmd;
uint16_t mdlid = ntohs(cmdlast->mdl);
- mcap4B_rsp *rsp = (mcap4B_rsp *)cmd;
GError *gerr = NULL;
gboolean close = FALSE;
gboolean notify = FALSE;
@@ -1410,23 +1397,13 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->req = MCL_AVAILABLE;
if (gerr) {
- if (!mdl) {
- /* Deletion of all mdls failed */
- g_slist_foreach(mcl->mdls, restore_mdl, NULL);
- } else if ((len >= MIN_RSP_LEN) &&
- (rsp->rc == MCAP_INVALID_MDL)) {
- /* Mdl does not exist in remote side */
- goto del_mdl;
- } else if (g_slist_find(mdl->mcl->mdls, mdl)){
- /* this mdl couldn't be deleted */
+ if (mdl)
restore_mdl(mdl, NULL);
- } else {
- /* MDL deleted request was sent by remote side while an
- * outgoing request for delete it was pending */
- shutdown_mdl(mdl);
- g_free(mdl);
- }
- goto end;
+ else
+ g_slist_foreach(mcl->mdls, restore_mdl, NULL);
+ deleted_cb(gerr, user_data);
+ g_error_free(gerr);
+ return close;
}
if (mdlid == MCAP_ALL_MDLIDS) {
@@ -1436,14 +1413,12 @@ static gboolean process_md_delete_mdl_rsp(struct mcap_mcl *mcl, uint8_t *cmd,
mcl->state = MCL_CONNECTED;
goto end;
}
-del_mdl:
+
mcl->mdls = g_slist_remove(mcl->mdls, mdl);
update_mcl_state(mcl);
mcap_delete_mdl(mdl, ¬ify);
end:
deleted_cb(gerr, user_data);
- if (gerr)
- g_error_free(gerr);
return close;
}
@@ -1481,30 +1456,6 @@ static void proc_response(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
}
}
-static void rsend_req(struct mcap_mcl *mcl)
-{
- uint8_t *cmd = mcl->lcmd;
- int len;
-
- if (!cmd)
- return;
-
- switch (cmd[0]) {
- case MCAP_MD_RECONNECT_MDL_REQ:
- case MCAP_MD_ABORT_MDL_REQ:
- case MCAP_MD_DELETE_MDL_REQ:
- len = 3;
- break;
- case MCAP_MD_CREATE_MDL_REQ:
- len = 5;
- break;
- default:
- return;
- }
-
- mcap_send_data(g_io_channel_unix_get_fd(mcl->cc), cmd, len);
-}
-
static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
{
if ((cmd[0] >= MCAP_MD_SYNC_CAP_REQ) &&
@@ -1526,8 +1477,7 @@ static void proc_cmd(struct mcap_mcl *mcl, uint8_t *cmd, uint32_t len)
/* ignore */
return;
proc_req[mcl->state](mcl, cmd, len);
- /* Initiator will ignore our last request => re-send */
- rsend_req(mcl);
+ /* Initiator will ignore our last request */
return;
}
proc_response(mcl, cmd, len);
--
1.6.3.3
^ permalink raw reply related
* [PATCH 42/60] Move assignment of data channel configuration
From: Jose Antonio Santos Cadenas @ 2010-07-22 8:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jose Antonio Santos Cadenas
In-Reply-To: <1279789001-4587-23-git-send-email-santoscadenas@gmail.com>
---
mcap/mcap.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/mcap/mcap.c b/mcap/mcap.c
index 1d33452..ff6766d 100644
--- a/mcap/mcap.c
+++ b/mcap/mcap.c
@@ -955,8 +955,6 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
- cfga = conf = req->conf;
-
mdl = get_mdl(mcl, mdl_id);
if (mdl && mdl->state == MDL_WAITING) {
/* A remote petition is also triying to connect this mdl_id
@@ -964,7 +962,9 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
send4B_cmd(mcl, MCAP_MD_CREATE_MDL_RSP, MCAP_MDL_BUSY, mdl_id);
return;
}
+
/* Callback to upper layer */
+ cfga = conf = req->conf;
rsp = mcl->cb->mdl_conn_req(mcl, mdep_id, mdl_id, &conf,
mcl->cb->user_data);
if (mcl->state == MCL_IDLE) {
@@ -985,7 +985,6 @@ static void process_md_create_mdl_req(struct mcap_mcl *mcl, uint8_t *cmd,
return;
}
-
if (!mdl) {
mdl = g_malloc0(sizeof(struct mcap_mdl));
mdl->mcl = mcl;
--
1.6.3.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox