All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RFC] update lib_package.bbclass
From: Koen Kooi @ 2010-10-20  7:47 UTC (permalink / raw)
  To: openembedded-devel
In-Reply-To: <4CBDDD0D.1080303@opendreambox.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 19-10-10 20:01, Andreas Oberritter wrote:
> On 10/18/2010 01:41 PM, Andreas Oberritter wrote:
>> On 10/18/2010 12:48 PM, Koen Kooi wrote:
>>>
>>> Well, .a files are supposed to go into -static, not into -dev.
>>>
> 
> [...]
> 
>> The problem was that I trusted lib_package to do the right thing. So the
>> real fix would be to add a -static package to lib_package.bbclass and to
>> add RDEPENDS_${PN}-static += "${PN}-dev" somewhere, because static libs
>> don't make much sense without develompent headers, right?
>>
>> Of course, this would create a different problem with upgrades, but I
>> would suspect that the number of users of static libraries on their
>> target machines is relatively small and, because a disappearing static
>> library doesn't create runtime problems, the installation of a new
>> -static package wouldn't impose a huge burden to the user.
>>
>> In case this solution was accepted: What's the policy for changing files
>> like lib_package.bbclass, in order to trigger an update of all relevant
>> packages? To bump every single PR?
> 
> I looked deeper into lib_package.bbclass and its history and I saw that
> it wasn't updated very often during the last years. It still uses
> hardcoded paths and doesn't include some files which would get packaged
> without lib_package.bbclass.
> 
> What lib_package.bbclass does now, compared to the defaults from
> bitbake.conf:
> 
> 1.) It adds ${libdir}/*.a and /lib/*.a to FILES_${PN}-dev.
> 
> 2.) It adds ${bindir}/*-config to FILES_${PN}-dev.
> 
> 3.) It creates an additional package ${PN}-bin, which contains all other
> executables: ${bindir}/* ${sbindir}/* /bin/* /sbin/*
> 
> 4.) It doesn't package any of the following:
>             ${datadir}/pixmaps ${datadir}/applications \
>             ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
>             ${libdir}/bonobo/servers
> 
> In f624db1d3c7de3fcb3a9e76d388a8f9f8fedcf5c, Koen introduced
> ${PN}-static packages, but lib_package.bbclass has not been updated
> since then, which was one year ago.
> 
> Although it packages ${bindir}/*-config into FILES_${PN}-dev, it does
> not include the required mangling applied by binconfig.bbclass. I think
> that's wrong and just causes unnecessary confusion. IMO, lib_package
> should either inherit binconfig or not, but leave FILES_${PN}-dev
> untouched in any case.
> 
> Leaving FILES_${PN}-dev untouched would also allow lib_package to
> automatically inherit some updates from bitbake.conf and to create
> non-empty ${PN}-static packages.
> 
> I don't know whether #4 should be changed or whether those directories
> were left out on purpose.
> 
> So, my current proposal looks like this:
> 
> -
> inherit binconfig	# ... or not
> 
> PACKAGES += "${PN}-bin"
> 
> FILES_${PN} = "${libexecdir}/* ${libdir}/lib*${SOLIBS} \
>             ${sysconfdir} ${sharedstatedir} ${localstatedir} \
>             ${base_libdir}/*${SOLIBS} \
>             ${datadir}/${PN} ${libdir}/${PN}/*"
> 
> FILES_${PN}-bin = "${bindir}/* ${sbindir}/* \
>                 ${base_bindir}/* ${base_sbindir}/*"
> -
> 

How about this one:

inherit binconfig

PACKAGES =+ "${PN}-bin"
FILES_${PN}-bin = "${bindir}/* ${sbindir}/* \
                   ${base_bindir}* ${base_sbindir}/*"


Does that work for you?

regards,

Koen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFMvp6FMkyGM64RGpERAmsTAJ0YDhVIcbXL59cei5Jrturv3zn6HwCfXydS
APscbmlBpvYasE+7O+99ksE=
=G5lN
-----END PGP SIGNATURE-----




^ permalink raw reply

* Re: [PATCH resend 5/9] MIPS: sync after cacheflush
From: Gleb O. Raiko @ 2010-10-20  8:05 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Ralf Baechle, Kevin Cernekee, Shinya Kuribayashi, linux-mips,
	linux-kernel
In-Reply-To: <alpine.LFD.2.00.1010192039550.15889@eddie.linux-mips.org>

On 20.10.2010 0:11, Maciej W. Rozycki wrote:
>   That said, R4k DECstations seem to perform aggressive write buffering in
> the chipset and to make sure a write has propagated to an MMIO register a
> SYNC and an uncached read operation are necessary.

Just uncached read may be enough. R4k shall pull data from its store 
buffer on uncached read.

>   I haven't investigated DMA dependencies and I think we currently only
> have one TURBOchannel device/driver only (that is the DEFTA/defxx FDDI
> thingy) making use of the generic DMA API on DECstations.  It seemed to
> work correctly the last time I tried; presumably either because the API
> Does The Right Thing, or by pure luck and right timings.

dfx_writel issues sync after store. BTW, it seems no uncached read 
issued here (just mb() is used, which seems to do sync only), so either 
those uncached read is not needed (unlikely) or data from dfx_writel 
wait somewhere in the chipset for being pulled by subsequent reads or 
writes.

Gleb.

^ permalink raw reply

* Re: [PATCH] diff: handle lines containing only whitespace better
From: Nazri Ramliy @ 2010-10-20  7:51 UTC (permalink / raw)
  To: Kevin Ballard; +Cc: Junio C Hamano, git
In-Reply-To: <780B144B-03E0-4ED5-8E92-D4EB3CBBBF71@sb.org>

On Wed, Oct 20, 2010 at 2:38 PM, Kevin Ballard <kevin@sb.org> wrote:
> ... I can also attempt to write
> tests if you can give me some guidance on how to deal with the need for ansi
> color codes.

Have a look at t/t4207-log-decoration-colors.sh for inspiration.

nazri

^ permalink raw reply

* [PATCH] phonet: remove the unused variable pn
From: Changli Gao @ 2010-10-20  7:51 UTC (permalink / raw)
  To: Remi Denis-Courmont; +Cc: David S. Miller, netdev, Changli Gao

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
 net/phonet/pep.c |    1 -
 1 file changed, 1 deletion(-)
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 9c903f9..3e60f2e 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -300,7 +300,6 @@ static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
 
 static int pipe_handler_enable_pipe(struct sock *sk, int enable)
 {
-	struct pep_sock *pn = pep_sk(sk);
 	int utid, req;
 
 	if (enable) {

^ permalink raw reply related

* Re: [PATCH v5] GPIO: add support for 74x164 serial-in/parallel-out 8-bit shift register
From: Miguel Ojeda @ 2010-10-20  7:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Florian Fainelli, David Brownell, Willy Tarreau, linux-kernel,
	Samuel Ortiz, Miguel Gaio, dbrownell, Juhos Gabor
In-Reply-To: <20101019160010.45750e1c.akpm@linux-foundation.org>

On Wed, Oct 20, 2010 at 1:00 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Tue, 19 Oct 2010 09:26:42 +0200
> Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>
>> On Mon, Oct 18, 2010 at 9:35 PM, Florian Fainelli <florian@openwrt.org> wrote:
>> > From: Miguel Gaio <miguel.gaio@efixo.com>
>> >
>> > This patch adds support for generic 74x164 serial-in/parallel-out 8-bits
>> > shift register. This driver can be used as a GPIO output expander.
>> >
>> ...
>> > +struct gen_74x164_chip {
>> > +       struct spi_device       *spi;
>> > +       struct gpio_chip        gpio_chip;
>> > +       struct mutex            lock;
>> > +       u8                      port_config;
>> > +};
>> ...
>> > +static void gen_74x164_set_value(struct gpio_chip *gc,
>> > +               unsigned offset, int val)
>> > +{
>> > +       struct gen_74x164_chip *chip = gpio_to_chip(gc);
>> > +       bool refresh;
>> > +
>> > +       mutex_lock(&chip->lock);
>> > +       if (val)
>> > +               chip->port_config |= (1 << offset);
>> > +       else
>> > +               chip->port_config &= ~(1 << offset);
>>
>> set_bit(), clear_bit() ?
>
> They're only to be used on `unsigned long' types, and `port_config' is
> u8.
>

Right as always! Maybe BIT()? Don't we have a {SET,CLEAR}_BIT()-like
macros somewhere?

#define SET_BIT(var,nr) (var) |= BIT((nr))
#define CLEAR_BIT(var,nr) (var) &= ~BIT((nr))
#define PUT_BIT(var,nr,value) do { \
        if ((value)) \
                SET_BIT((var), (nr)); \
        else \
                CLEAR_BIT((var), (nr)); \
} while(0)

May I make a patch and try to see who could use it? I suppose a
Coccinelle's semantic patch would be great here.

^ permalink raw reply

* [U-Boot] [PATCH] autocomplete: remove runtime handler install
From: Mike Frysinger @ 2010-10-20  7:52 UTC (permalink / raw)
  To: u-boot

Rather than add runtime overhead of installing completion handlers, do it
statically at build time.  This requires a new build time helper macro to
declare a command and the completion handler at the same time.  Then we
convert the env related funcs over to this.

This gives an opportunity to also unify the U_BOOT_CMD macros.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 common/cmd_nvedit.c |   20 ++++++++++++--------
 common/command.c    |   24 ------------------------
 common/main.c       |    4 ----
 include/command.h   |   30 ++++++++++++++++++------------
 4 files changed, 30 insertions(+), 48 deletions(-)

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 3d30c32..be7a878 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -886,29 +886,32 @@ U_BOOT_CMD(
  */
 
 #if defined(CONFIG_CMD_EDITENV)
-U_BOOT_CMD(
+U_BOOT_CMD_COMPLETE(
 	editenv, 2, 0,	do_env_edit,
 	"edit environment variable",
 	"name\n"
-	"    - edit environment variable 'name'"
+	"    - edit environment variable 'name'",
+	var_complete
 );
 #endif
 
-U_BOOT_CMD(
+U_BOOT_CMD_COMPLETE(
 	printenv, CONFIG_SYS_MAXARGS, 1,	do_env_print,
 	"print environment variables",
 	"\n    - print values of all environment variables\n"
 	"printenv name ...\n"
-	"    - print value of environment variable 'name'"
+	"    - print value of environment variable 'name'",
+	var_complete
 );
 
-U_BOOT_CMD(
+U_BOOT_CMD_COMPLETE(
 	setenv, CONFIG_SYS_MAXARGS, 0,	do_env_set,
 	"set environment variables",
 	"name value ...\n"
 	"    - set environment variable 'name' to 'value ...'\n"
 	"setenv name\n"
-	"    - delete environment variable 'name'"
+	"    - delete environment variable 'name'",
+	var_complete
 );
 
 #if defined(CONFIG_CMD_ASKENV)
@@ -929,10 +932,11 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_RUN)
-U_BOOT_CMD(
+U_BOOT_CMD_COMPLETE(
 	run,	CONFIG_SYS_MAXARGS,	1,	do_run,
 	"run commands in an environment variable",
 	"var [...]\n"
-	"    - run the commands in the environment variable(s) 'var'"
+	"    - run the commands in the environment variable(s) 'var'",
+	var_complete
 );
 #endif
diff --git a/common/command.c b/common/command.c
index d47d719..f975701 100644
--- a/common/command.c
+++ b/common/command.c
@@ -175,30 +175,6 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
 	return 0;
 }
 
-static void install_auto_complete_handler(const char *cmd,
-		int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]))
-{
-	cmd_tbl_t *cmdtp;
-
-	cmdtp = find_cmd(cmd);
-	if (cmdtp == NULL)
-		return;
-
-	cmdtp->complete = complete;
-}
-
-void install_auto_complete(void)
-{
-#if defined(CONFIG_CMD_EDITENV)
-	install_auto_complete_handler("editenv", var_complete);
-#endif
-	install_auto_complete_handler("printenv", var_complete);
-	install_auto_complete_handler("setenv", var_complete);
-#if defined(CONFIG_CMD_RUN)
-	install_auto_complete_handler("run", var_complete);
-#endif
-}
-
 /*************************************************************************************/
 
 static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
diff --git a/common/main.c b/common/main.c
index 878cffd..42f4d02 100644
--- a/common/main.c
+++ b/common/main.c
@@ -336,10 +336,6 @@ void main_loop (void)
 	hush_init_var ();
 #endif
 
-#ifdef CONFIG_AUTO_COMPLETE
-	install_auto_complete();
-#endif
-
 #ifdef CONFIG_PREBOOT
 	if ((p = getenv ("preboot")) != NULL) {
 # ifdef CONFIG_AUTOBOOT_KEYED
diff --git a/include/command.h b/include/command.h
index 81aa019..d1a0fc0 100644
--- a/include/command.h
+++ b/include/command.h
@@ -74,7 +74,7 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
 extern int cmd_usage(cmd_tbl_t *cmdtp);
 
 #ifdef CONFIG_AUTO_COMPLETE
-extern void install_auto_complete(void);
+extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
 extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp);
 #endif
 
@@ -111,23 +111,29 @@ extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 #define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))
 
-#ifdef  CONFIG_SYS_LONGHELP
+#ifdef CONFIG_AUTO_COMPLETE
+# define _CMD_COMPLETE(x) x,
+#else
+# define _CMD_COMPLETE(x)
+#endif
+#ifdef CONFIG_SYS_LONGHELP
+# define _CMD_HELP(x) x,
+#else
+# define _CMD_HELP(x)
+#endif
 
-#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
-cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
+#define U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
+	{#name, maxargs, rep, cmd, usage, _CMD_HELP(help) _CMD_COMPLETE(comp)}
 
 #define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \
-{#name, maxargs, rep, cmd, usage, help}
+	U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
 
-#else	/* no long help info */
+#define U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
+	cmd_tbl_t __u_boot_cmd_##name Struct_Section = \
+		U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp)
 
 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
-cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}
-
-#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \
-{#name, maxargs, rep, cmd, usage}
-
-#endif	/* CONFIG_SYS_LONGHELP */
+	U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
 
 #if !defined(CONFIG_RELOC_FIXUP_WORKS)
 void fixup_cmdtable(cmd_tbl_t *cmdtp, int size);
-- 
1.7.3.1

^ permalink raw reply related

* Re: [PATCH 1/2]percpu: introduce read mostly percpu API
From: Eric Dumazet @ 2010-10-20  7:53 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Shaohua Li, lkml, Ingo Molnar, hpa@zytor.com, Chen, Tim C
In-Reply-To: <20101020073511.GC20124@basil.fritz.box>

Le mercredi 20 octobre 2010 à 09:35 +0200, Andi Kleen a écrit :
> On Wed, Oct 20, 2010 at 07:18:00AM +0200, Eric Dumazet wrote:
> > Le mercredi 20 octobre 2010 à 11:07 +0800, Shaohua Li a écrit :
> > > Add a new readmostly percpu section and api, next patch will use it.
> > > 
> > > Signed-off-by: Shaohua Li <shaohua.li@intel.com>
> > > ---
> > 
> > 
> > Could you precisely describe why grouping together read mostly percpu
> > variables is a win ? Especially when you add in your next patch a single
> > variable ?
> 
> Not Shaohua, but I can explain it:
> 
> There is some per cpu data which is read by other CPUs. In this 
> case it's a win to use the separate section because you avoid false sharing 
> and the cache line can be kept in shared mode on all CPUs.
> 
> The next patch has an example of such data: data which is read
> by another CPU to send something to the target CPU.
> 
> I think the concept is useful and makes a lot of sense.
> The alternative would be __read_mostly NR_CPUS arrays, but 
> we all know that is a bad idea because it wastes too much memory
> on CONFIG_MAX_SMP setups.
> 

My question was more a rethoric one. I understand for sure the intent.

All this should be explained in changelog, so that people know
when/where use this new class of per_cpu variables ;)

Thanks



^ permalink raw reply

* [patch 1/9] efikamx: read board id
From: Amit Kucheria @ 2010-10-20  7:54 UTC (permalink / raw)
  To: linux-arm-kernel
In-Reply-To: <AANLkTi=SbFy1eFzQ3XUGDjurme=stUSiqmTRVR=EtX5q@mail.gmail.com>

On 10 Oct 19, Matt Sealey wrote:
> On Tue, Oct 19, 2010 at 4:15 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > On Tue, Oct 19, 2010 at 10:42:54PM +0200, Arnaud Patard wrote:
> >> read board id value from the GPIO3_16/17/11
> >>
> >>
> >> +/* ? PCBID2 ?PCBID1 PCBID0 ?STATE
> >> + ? ? 1 ? ? ? 1 ? ? ?1 ? ?ER1:rev1.1
> >> + ? ? 1 ? ? ? 1 ? ? ?0 ? ?ER2:rev1.2
> >> + ? ? 1 ? ? ? 0 ? ? ?1 ? ?ER3:rev1.3
> >> + ? ? 1 ? ? ? 0 ? ? ?0 ? ?ER4:rev1.4
> >> +*/
> >> +static void __init mx51_efikamx_board_id(void)
> >> +{
> >> + ? ? int id;
> >> +
> >> + ? ? /* things are taking time to settle */
> >> + ? ? msleep(500);
> >
> > Is it really necessary to delay the boot process such a long time?
> 
> Yes. On older boards the PCBID pins are pulled high by IOMUX settings
> (a pulldown on the board on newer revisions will keep it down). IOMUX
> and GPIO stuff takes a little while to settle in, so if you do it
> immediately, it will return some freakish values based on random GPIO
> setup (it may be high, low, or none of the above at any point before
> the pad setting kicks in).

Then perhaps do this only for the older boards?

So by default there is no delay, but when a (new) config option is enabled,
delay boot.

^ permalink raw reply

* [PATCH 0/1] Add Sim Access plugin
From: Waldemar Rymarkiewicz @ 2010-10-20  7:55 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: Marcel Holtmann, suraj, Johan Hedberg, joakim.xj.ceder,
	arunkr.singh, Waldemar Rymarkiewicz

Hi,
Sorry, I sent on to wrong list, so agian ...

Here you are the SAP plugin modified to reflect the audio/telephony design. 
Could anyone interested in do a review and put any comments.

Regards,
/Waldek


Waldemar Rymarkiewicz (1):
  Add Sim Access Plugin

 .gitignore      |    1 +
 Makefile.am     |   25 +-
 acinclude.m4    |   14 +
 doc/sap-api.txt |   57 ++
 sap/main.c      |   54 ++
 sap/manager.c   |   94 ++++
 sap/manager.h   |   21 +
 sap/sap-dummy.c |  306 +++++++++++
 sap/sap-ste.c   | 1265 ++++++++++++++++++++++++++++++++++++++++++++++
 sap/sap.h       |  187 +++++++
 sap/server.c    | 1516 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sap/server.h    |   23 +
 12 files changed, 3559 insertions(+), 4 deletions(-)
 create mode 100644 doc/sap-api.txt
 create mode 100644 sap/main.c
 create mode 100644 sap/manager.c
 create mode 100644 sap/manager.h
 create mode 100644 sap/sap-dummy.c
 create mode 100644 sap/sap-ste.c
 create mode 100644 sap/sap.h
 create mode 100644 sap/server.c
 create mode 100644 sap/server.h

^ permalink raw reply

* [PATCH 1/1] Add Sim Access Plugin
From: Waldemar Rymarkiewicz @ 2010-10-20  7:55 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: Marcel Holtmann, suraj, Johan Hedberg, joakim.xj.ceder,
	arunkr.singh, Waldemar Rymarkiewicz
In-Reply-To: <1287561308-18611-1-git-send-email-waldemar.rymarkiewicz@tieto.com>

Sim Access plugin implements Sim Access Profile server role
according to the Bluetooth Sim Access Profile v1.1 specification.
---
 .gitignore      |    1 +
 Makefile.am     |   25 +-
 acinclude.m4    |   14 +
 doc/sap-api.txt |   57 ++
 sap/main.c      |   54 ++
 sap/manager.c   |   94 ++++
 sap/manager.h   |   21 +
 sap/sap-dummy.c |  306 +++++++++++
 sap/sap-ste.c   | 1265 ++++++++++++++++++++++++++++++++++++++++++++++
 sap/sap.h       |  187 +++++++
 sap/server.c    | 1516 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sap/server.h    |   23 +
 12 files changed, 3559 insertions(+), 4 deletions(-)
 create mode 100644 doc/sap-api.txt
 create mode 100644 sap/main.c
 create mode 100644 sap/manager.c
 create mode 100644 sap/manager.h
 create mode 100644 sap/sap-dummy.c
 create mode 100644 sap/sap-ste.c
 create mode 100644 sap/sap.h
 create mode 100644 sap/server.c
 create mode 100644 sap/server.h

diff --git a/.gitignore b/.gitignore
index 07e239f..3e36a59 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@ lib/bluetooth
 src/builtin.h
 src/bluetoothd
 audio/telephony.c
+sap/sap.c
 scripts/bluetooth.rules
 scripts/97-bluetooth.rules
 scripts/97-bluetooth-hid2hci.rules
diff --git a/Makefile.am b/Makefile.am
index 6e8fc7d..015d84e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,6 +142,20 @@ audio_libtelephony_a_SOURCES = audio/telephony.h audio/telephony-dummy.c \
 				audio/telephony-maemo6.c
 endif
 
+if SAPPLUGIN
+builtin_modules += sap
+builtin_sources += sap/main.c \
+			sap/manager.h sap/manager.c \
+			sap/server.h sap/server.c \
+			sap/sap.h
+builtin_nodist += sap/sap.c
+
+noinst_LIBRARIES = sap/libsap.a
+
+sap_libsap_a_SOURCES = sap/sap.h sap/sap-dummy.c \
+				sap/sap-ste.c
+endif
+
 if INPUTPLUGIN
 builtin_modules += input
 builtin_sources += input/main.c \
@@ -263,8 +277,8 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \
 			input/input.conf serial/serial.conf \
 			audio/audio.conf audio/telephony-dummy.c \
 			audio/telephony-maemo5.c audio/telephony-ofono.c \
-			audio/telephony-maemo6.c
-
+			audio/telephony-maemo6.c \
+			sap/sap-dummy.c sap/sap-ste.c
 
 if ALSA
 alsadir = $(libdir)/alsa-lib
@@ -352,7 +366,7 @@ EXTRA_DIST += doc/manager-api.txt \
 		doc/service-api.txt doc/agent-api.txt doc/attribute-api.txt \
 		doc/serial-api.txt doc/network-api.txt \
 		doc/input-api.txt doc/audio-api.txt doc/control-api.txt \
-		doc/hfp-api.txt doc/assigned-numbers.txt
+		doc/hfp-api.txt doc/assigned-numbers.txt doc/sap-api.txt
 
 AM_YFLAGS = -d
 
@@ -387,6 +401,9 @@ src/builtin.h: src/genbuiltin $(builtin_sources)
 audio/telephony.c: audio/@TELEPHONY_DRIVER@
 	$(AM_V_GEN)$(LN_S) $(abs_top_srcdir)/$< $@
 
+sap/sap.c: sap/@SAP_DRIVER@
+	$(AM_V_GEN)$(LN_S) $(abs_top_srcdir)/$< $@
+
 scripts/%.rules:
 	$(AM_V_GEN)cp $(subst 97-,,$@) $@
 
@@ -397,4 +414,4 @@ lib/bluetooth/%.h: lib/%.h
 	$(AM_V_GEN)$(LN_S) $(abs_top_srcdir)/$< $@
 
 clean-local:
-	$(RM) -r lib/bluetooth
+	$(RM) -r lib/bluetooth
\ No newline at end of file
diff --git a/acinclude.m4 b/acinclude.m4
index 287f07d..093e9a6 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -174,6 +174,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	input_enable=yes
 	serial_enable=yes
 	network_enable=yes
+	sap_enable=yes
 	service_enable=yes
 	health_enable=no
 	pnat_enable=no
@@ -193,6 +194,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	configfiles_enable=yes
 	telephony_driver=dummy
 	maemo6_enable=no
+	sap_driver=dummy
 
 	AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable code optimization]), [
 		optimization_enable=${enableval}
@@ -210,6 +212,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 		network_enable=${enableval}
 	])
 
+	AC_ARG_ENABLE(sap, AC_HELP_STRING([--disable-sap], [disable sap plugin]), [
+		sap_enable=${enableval}
+	])
+
 	AC_ARG_ENABLE(serial, AC_HELP_STRING([--disable-serial], [disable serial plugin]), [
 		serial_enable=${enableval}
 	])
@@ -320,6 +326,13 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 		hal_enable=${enableval}
 	])
 
+	AC_ARG_WITH(sap, AC_HELP_STRING([--with-sap=DRIVER], [select SAP driver]), [
+		sap_driver=${withval}
+	])
+
+
+	AC_SUBST([SAP_DRIVER], [sap-${sap_driver}.c])
+
 	if (test "${fortify_enable}" = "yes"); then
 		CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
 	fi
@@ -351,6 +364,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	AM_CONDITIONAL(INPUTPLUGIN, test "${input_enable}" = "yes")
 	AM_CONDITIONAL(SERIALPLUGIN, test "${serial_enable}" = "yes")
 	AM_CONDITIONAL(NETWORKPLUGIN, test "${network_enable}" = "yes")
+	AM_CONDITIONAL(SAPPLUGIN, test "${sap_enable}" = "yes")
 	AM_CONDITIONAL(SERVICEPLUGIN, test "${service_enable}" = "yes")
 	AM_CONDITIONAL(HEALTHPLUGIN, test "${health_enable}" = "yes")
 	AM_CONDITIONAL(MCAP, test "${health_enable}" = "yes")
diff --git a/doc/sap-api.txt b/doc/sap-api.txt
new file mode 100644
index 0000000..7951f56
--- /dev/null
+++ b/doc/sap-api.txt
@@ -0,0 +1,57 @@
+BlueZ D-Bus Sim Access Profile API description
+***********************************
+
+Copyright (C) 2010 ST-Ericsson SA
+
+
+Sim Access Profile hierarchy
+============================
+
+Service		org.bluez
+Interface	org.bluez.SimAccess
+Object path	[variable prefix]/{hci0,hci1,...}
+
+Methods		void Enable()
+
+			Start up SAP server and register SDP record for it.
+
+			Possible errors: org.bluez.Error.Failed
+
+		void Disable()
+
+			Shudown SAP server and remove the SDP record.
+
+			Possible errors: org.bluez.Error.Failed
+
+		void Disconnect(boolean type)
+
+			Disconnect SAP client from the server. The 'type'
+			parameter indicates disconnection type.
+
+			True  - gracefull disconnection
+			False - immediate disconnection
+
+			Possible errors: org.bluez.Error.Failed
+
+		dict GetProperties()
+
+			Return all properties for the interface. See the
+			properties section for available properties.
+
+			Possible Errors: org.bluez.Error.Failed
+
+Signals		PropertyChanged(string name, variant value)
+
+			This signal indicates a changed value of the given
+			property.
+
+
+Properties	boolean Enabled [readonly]
+
+				Indicates the state of the server. True if the server
+				is enabled and False otherwise.
+
+			boolean Connected [readonly]
+
+				Indicates if SAP client is connected to the server.
+
diff --git a/sap/main.c b/sap/main.c
new file mode 100644
index 0000000..b3efcf8
--- /dev/null
+++ b/sap/main.c
@@ -0,0 +1,54 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <gdbus.h>
+#include "plugin.h"
+#include "manager.h"
+
+static DBusConnection *connection;
+
+static int sap_init(void)
+{
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+
+	if (!connection)
+		return -EIO;
+
+	if (sap_manager_init(connection) < 0) {
+		dbus_connection_unref(connection);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static void sap_exit(void)
+{
+	sap_manager_exit();
+
+	dbus_connection_unref(connection);
+}
+
+BLUETOOTH_PLUGIN_DEFINE(sap, VERSION,
+		BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, sap_init, sap_exit)
diff --git a/sap/manager.c b/sap/manager.c
new file mode 100644
index 0000000..972a46b
--- /dev/null
+++ b/sap/manager.c
@@ -0,0 +1,94 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
+
+#include <gdbus.h>
+
+#include "log.h"
+#include "adapter.h"
+#include "device.h"
+
+#include "manager.h"
+
+#include "server.h"
+
+static DBusConnection *connection = NULL;
+
+
+static int sap_server_probe(struct btd_adapter *adapter)
+{
+	const gchar *path = adapter_get_path(adapter);
+	bdaddr_t src;
+
+	DBG("path %s", path);
+
+	adapter_get_address(adapter, &src);
+
+	return sap_server_register(path, &src);
+}
+
+static void sap_server_remove(struct btd_adapter *adapter)
+{
+	const gchar *path = adapter_get_path(adapter);
+
+	DBG("path %s", path);
+
+	sap_server_unregister(path);
+}
+
+static struct btd_adapter_driver sap_server_driver = {
+	.name	= "sap-server",
+	.probe	= sap_server_probe,
+	.remove	= sap_server_remove,
+};
+
+int sap_manager_init(DBusConnection *conn)
+{
+	connection = dbus_connection_ref(conn);
+
+	if (sap_server_init(connection) < 0) {
+		error("Can't init SAP server");
+		dbus_connection_unref(conn);
+		return -1;
+	}
+
+	btd_register_adapter_driver(&sap_server_driver);
+
+	return 0;
+}
+
+void sap_manager_exit(void)
+{
+	btd_unregister_adapter_driver(&sap_server_driver);
+
+	dbus_connection_unref(connection);
+	connection = NULL;
+
+	sap_server_exit();
+}
diff --git a/sap/manager.h b/sap/manager.h
new file mode 100644
index 0000000..5a779df
--- /dev/null
+++ b/sap/manager.h
@@ -0,0 +1,21 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+int sap_manager_init(DBusConnection *conn);
+void sap_manager_exit(void);
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
new file mode 100644
index 0000000..db1078b
--- /dev/null
+++ b/sap/sap-dummy.c
@@ -0,0 +1,306 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 ST-Ericsson SA
+ *
+ *  Author: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> for ST-Ericsson
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "log.h"
+#include "sap.h"
+
+#define SAP_DUMMY_IFACE "org.bluez.SimAccessTest"
+#define SAP_DUMMY_PATH "/org/bluez/test"
+#define SAP_ONGOING_CALL_TIMER 5
+
+typedef enum {
+	SIM_CONNECTED	= 0x00,
+	SIM_DISCONNECTED= 0x01,
+	SIM_POWERED_OFF	= 0x02,
+	SIM_MISSING	= 0x03
+} sim_connection_status_t;
+
+static DBusConnection *connection = NULL;
+
+static sim_connection_status_t sim_card_connection_status = SIM_DISCONNECTED;
+static void *		sap_data = NULL;  /* SAP server private data.*/
+static gboolean		ongoing_call_status = FALSE;
+static int		max_msg_size_supported = 512;
+
+void sap_connect_req(void *sap_device, uint16_t maxmsgsize)
+{
+	if (sim_card_connection_status != SIM_CONNECTED) {
+		sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED,
+								maxmsgsize);
+		return;
+	} else if(max_msg_size_supported > maxmsgsize) {
+		sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL,
+						max_msg_size_supported);
+		return;
+	}else if (max_msg_size_supported < maxmsgsize) {
+		sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED,
+					max_msg_size_supported);
+		return;
+	} else if(ongoing_call_status) {
+		sap_connect_rsp(sap_device, SAP_STATUS_OK_ONGOING_CALL,
+								maxmsgsize);
+		//run_timer
+		return;
+	} else {
+		sim_card_connection_status = SIM_CONNECTED;
+		sap_data = sap_device;
+
+		sap_connect_rsp(sap_device, SAP_STATUS_OK, maxmsgsize);
+		sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
+	}
+}
+
+void sap_disconnect_req(void *sap_device, uint8_t linkloss)
+{
+	sim_card_connection_status = SIM_DISCONNECTED;
+	sap_data = NULL;
+	ongoing_call_status = FALSE;
+
+	if(linkloss)
+		return;
+
+	sap_disconnect_rsp(sap_device);
+}
+
+void sap_transfer_apdu_req(void *sap_device, sap_parameter *param)
+{
+	if (sim_card_connection_status == SIM_MISSING)
+		sap_transfer_apdu_rsp(sap_device, SAP_RESULT_ERROR_CARD_REMOVED,
+								NULL, 0);
+	else if (sim_card_connection_status == SIM_POWERED_OFF)
+		sap_transfer_apdu_rsp(sap_device, SAP_RESULT_ERROR_POWERED_OFF,
+								NULL, 0);
+	else if (sim_card_connection_status != SIM_CONNECTED)
+		sap_transfer_apdu_rsp(sap_device, SAP_RESULT_ERROR_NOT_ACCESSIBLE,
+								NULL, 0);
+	else
+		sap_transfer_apdu_rsp(sap_device, SAP_RESULT_OK, NULL, 0);
+}
+
+void sap_transfer_atr_req(void * sap_device)
+{
+	uint8_t atr[] = {0x3b, 0x9a, 0x96, 0x00, 0x92, 0x01, 0x98, 0x93, 0x17,
+			 0x00, 0x02, 0x28, 0x03, 0x00};
+
+	if (sim_card_connection_status == SIM_MISSING)
+		sap_transfer_atr_rsp(sap_device, SAP_RESULT_ERROR_CARD_REMOVED,
+								NULL, 0);
+	else if (sim_card_connection_status == SIM_POWERED_OFF)
+		sap_transfer_atr_rsp(sap_device, SAP_RESULT_ERROR_POWERED_OFF,
+								NULL, 0);
+	else if (sim_card_connection_status != SIM_CONNECTED)
+		sap_transfer_atr_rsp(sap_device, SAP_RESULT_ERROR_NO_REASON,
+								NULL, 0);
+	else
+		sap_transfer_atr_rsp(sap_device, SAP_RESULT_OK, atr, 0x0E);
+}
+
+void sap_power_sim_off_req(void *sap_device)
+{
+	if(sim_card_connection_status == SIM_MISSING)
+		sap_power_sim_off_rsp(sap_device, SAP_RESULT_ERROR_CARD_REMOVED);
+	else if (sim_card_connection_status == SIM_POWERED_OFF)
+		sap_power_sim_off_rsp(sap_device, SAP_RESULT_ERROR_POWERED_OFF);
+	else if(sim_card_connection_status != SIM_CONNECTED)
+		sap_power_sim_off_rsp(sap_device, SAP_RESULT_ERROR_NO_REASON);
+	else {
+		sap_power_sim_off_rsp(sap_device, SAP_RESULT_OK);
+		sim_card_connection_status = SIM_POWERED_OFF;
+	}
+}
+
+void sap_power_sim_on_req(void *sap_device)
+{
+	if (sim_card_connection_status == SIM_MISSING)
+		sap_power_sim_on_rsp(sap_device, SAP_RESULT_ERROR_CARD_REMOVED);
+	else if (sim_card_connection_status == SIM_POWERED_OFF) {
+		sap_power_sim_on_rsp(sap_device, SAP_RESULT_OK);
+		sim_card_connection_status = SIM_CONNECTED;
+		return;
+	}else if(sim_card_connection_status != SIM_CONNECTED)
+		sap_power_sim_on_rsp(sap_device, SAP_RESULT_ERROR_NOT_ACCESSIBLE);
+	else {
+		sap_power_sim_on_rsp(sap_device, SAP_RESULT_ERROR_NO_REASON);
+	}
+}
+
+void sap_reset_sim_req(void *sap_device)
+{
+	if (sim_card_connection_status == SIM_MISSING)
+		sap_reset_sim_rsp(sap_device, SAP_RESULT_ERROR_CARD_REMOVED);
+	else if (sim_card_connection_status == SIM_POWERED_OFF)
+		sap_reset_sim_rsp(sap_device, SAP_RESULT_ERROR_POWERED_OFF);
+	else if (sim_card_connection_status != SIM_CONNECTED)
+		sap_reset_sim_rsp(sap_device, SAP_RESULT_ERROR_NO_REASON);
+	else {
+		sap_reset_sim_rsp(sap_device, SAP_RESULT_OK);
+		sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
+	}
+}
+
+void sap_transfer_card_reader_status_req(void * sap_device)
+{
+	if (sim_card_connection_status != SIM_CONNECTED) {
+		sap_transfer_card_reader_status_rsp(sap_device,
+					SAP_RESULT_ERROR_NO_REASON, 0xF1);
+		return;
+	}
+	sap_transfer_card_reader_status_rsp(sap_device, SAP_RESULT_OK, 0xF1);
+}
+
+void sap_set_transport_protocol_req(void * sap_device,sap_parameter * param)
+{
+	sap_transport_protocol_rsp(sap_device, SAP_RESULT_NOT_SUPPORTED);
+}
+
+static inline DBusMessage *invalid_args(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, "org.bluez.Error.InvalidArguments",
+					"Invalid arguments in method call");
+}
+
+static DBusMessage *ongoing_call(DBusConnection *conn, DBusMessage *msg,
+						void *data)
+{
+	dbus_bool_t ongoing;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &ongoing,
+						DBUS_TYPE_INVALID))
+		return invalid_args(msg);
+
+	if (ongoing_call_status && !ongoing) {
+		/* An ongoing call has finished. Continue connection.*/
+		sap_connect_rsp(sap_data, SAP_STATUS_OK, max_msg_size_supported);
+		sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_RESET);
+		ongoing_call_status = ongoing;
+	} else if (!ongoing_call_status && ongoing) {
+		/* An ongoing call has started.*/
+		ongoing_call_status = ongoing;
+	}
+
+	DBG("sap-dummy: OngoingCall status set to %d", ongoing_call_status);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *max_msg_size(DBusConnection *conn, DBusMessage *msg,
+						void *data)
+{
+	dbus_uint32_t size;
+
+	if (sim_card_connection_status == SIM_CONNECTED)
+		return g_dbus_create_error(msg, "org.bluez.Error.Failed",
+				"Can't change msg size when connected.");
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &size,
+						DBUS_TYPE_INVALID))
+		return invalid_args(msg);
+
+	max_msg_size_supported = size;
+
+	DBG("sap-dummy: MaxMessageSize set to %d", max_msg_size_supported);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,
+						void *data)
+{
+	sim_card_connection_status = SIM_DISCONNECTED;
+	sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_NOT_ACCESSIBLE);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *card_status(DBusConnection *conn, DBusMessage *msg,
+						void *data)
+{
+	dbus_uint32_t status;
+
+	if(sim_card_connection_status != SIM_CONNECTED)
+		return g_dbus_create_error(msg, "org.bluez.Error.Failed",
+				"Can't change msg size when connected.");
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &status,
+						DBUS_TYPE_INVALID))
+		return invalid_args(msg);
+
+	if (status) {
+		if (sim_card_connection_status == SIM_MISSING) {
+			sim_card_connection_status = SIM_CONNECTED;
+			sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_INSERTED);
+		}
+	} else {
+		sim_card_connection_status = SIM_MISSING;
+		sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_REMOVED);
+	}
+
+	DBG("sap-dummy: Card status changed to %d", status);
+
+	return dbus_message_new_method_return(msg);
+}
+
+
+static GDBusMethodTable dummy_methods[] = {
+	{ "OngoingCall",	"b",	"",	ongoing_call},
+	{ "MaxMessageSize",	"u",	"",	max_msg_size},
+	{ "Disconnect",		"",	"",	disconnect},
+	{ "CardStatus",		"u",	"",	card_status},
+	{ }
+};
+
+static GDBusSignalTable dummy_signals[] = {
+	{ "","" },
+	{ }
+};
+
+int sap_init(void)
+{
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+
+	if (g_dbus_register_interface(connection, SAP_DUMMY_PATH,
+					SAP_DUMMY_IFACE,
+					dummy_methods, dummy_signals,
+					NULL, NULL, NULL) == FALSE) {
+		error("sap-dummy interface %s init failed on path %s",
+			SAP_DUMMY_IFACE, SAP_DUMMY_PATH);
+		return -1;
+	}
+
+	return 0;
+}
+
+void sap_exit(void)
+{
+	dbus_connection_unref(connection);
+	connection = NULL;
+}
diff --git a/sap/sap-ste.c b/sap/sap-ste.c
new file mode 100644
index 0000000..e9f99b5
--- /dev/null
+++ b/sap/sap-ste.c
@@ -0,0 +1,1265 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 ST-Ericsson SA
+ *
+ *  Author: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> for
+ *  ST-Ericsson.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <glib.h>
+#include <unistd.h>
+
+#include "log.h"
+#include "sap.h"
+
+/** SAP_STE_MAX_MSG_SIZE - Maximum size of Sim Access Profile message
+ * supported by the server.
+ */
+#define SAP_STE_MAX_MSG_SIZE 	1024
+
+/** SAP_STE_MIN_MSG_SIZE - Minimal size of  Sim Access Profile message
+ * supported by the server.
+ */
+#define SAP_STE_MIN_MSG_SIZE 	512
+
+/** SAP_STE_UNIX_SOCKET_NAME - Unix socket name used to communicate with
+ * SIM daemon.
+ */
+#define SAP_STE_UNIX_SOCKET_NAME "/dev/socket/catd_a"
+
+/*Sizes of SIM message fields.*/
+#define SAP_STE_MSG_LEN_SIZE 		0x0002
+#define SAP_STE_MSG_TYPE_SIZE 		0x0002
+#define SAP_STE_MSG_CLIENT_TAG_SIZE 	0x0004
+#define SAP_STE_MSG_STATUS_SIZE 	0x0004
+
+/*Header size of SIM message */
+#define SAP_STE_MSG_HEADER_SIZE ((SAP_STE_MSG_LEN_SIZE) + \
+		(SAP_STE_MSG_TYPE_SIZE) + (SAP_STE_MSG_CLIENT_TAG_SIZE))
+
+#define SAP_STE_CLIENT_TAG 0x0000
+
+/** sap_ste_protocol_t - protocol used in communication with SIM.*/
+typedef enum {
+	SAP_STE_START_SAP_REQ 	= 0x2D01,
+	SAP_STE_START_SAP_RSP 	= 0x2E01,
+	SAP_STE_END_SAP_REQ	= 0x2D02,
+	SAP_STE_END_SAP_RSP 	= 0x2E02,
+	SAP_STE_POWER_OFF_REQ	= 0x2D03,
+	SAP_STE_POWER_OFF_RSP	= 0x2E03,
+	SAP_STE_POWER_ON_REQ 	= 0x2D04,
+	SAP_STE_POWER_ON_RSP	= 0x2E04,
+	SAP_STE_RESET_REQ	= 0x2D05,
+	SAP_STE_RESET_RSP	= 0x2E05,
+	SAP_STE_SEND_APDU_REQ	= 0x2D06,
+	SAP_STE_SEND_APDU_RSP	= 0x2E06,
+	SAP_STE_GET_ATR_REQ	= 0x2D07,
+	SAP_STE_GET_ATR_RSP	= 0x2E07,
+	SAP_STE_GET_STATUS_REQ	= 0x2D08,
+	SAP_STE_GET_STATUS_RSP	= 0x2E08,
+	SAP_STE_STATUS_IND	= 0x2F02
+} sap_ste_protocol_t;
+
+/** sap_ste_msg_t - Type of SIM message.*/
+typedef enum {
+	SAP_STE_SEND_APDU_MSG = 0,
+	SAP_STE_GET_ATR_MSG,
+	SAP_STE_POWER_OFF_MSG,
+	SAP_STE_POWER_ON_MSG,
+	SAP_STE_RESET_MSG,
+	SAP_STE_GET_STATUS_MSG,
+	SAP_STE_MSG_MAX,
+} sap_ste_msg_t;
+
+/** sap_ste_status_t - Status of a request.*/
+typedef enum {
+	SAP_STE_STATUS_OK 			= 0x00000000,
+	SAP_STE_STATUS_UNDEFINED_FAILURE 	= 0xFFFFFFFF,
+} sap_ste_status_t;
+
+/** sap_ste_card_status_t - Sim card status.*/
+typedef enum {
+	SAP_STE_CARD_STATUS_UNKNOWN = 0x00,
+	SAP_STE_CARD_STATUS_ACTIVE = 0x01,
+	SAP_STE_CARD_STATUS_NOT_ACTIVE = 0x02,
+	SAP_STE_CARD_STATUS_MISSING = 0x03,
+	SAP_STE_CARD_STATUS_INVALID = 0x04
+} sap_ste_card_status_t;
+
+/** SAP_STE_state_t - Sim connection state.*/
+typedef enum {
+		SAP_STE_DISABLED,	/* Reader not present or removed */
+		SAP_STE_POWERED_OFF,	/* Card in the reader but powered off */
+		SAP_STE_NO_CARD,	/* No card in the reader */
+		SAP_STE_ENABLED,	/* Card in the reader and powered on */
+		SAP_STE_STATE_MAX
+} sap_ste_state_t;
+
+/** sap_ste_message - Sim message format.
+ * @len;	Length of the message minus sizeof(len).
+ * @id;		Request type id.
+ * @client_tag;	SAP server cleint id.
+ * @payload;	Data.
+ */
+typedef struct {
+	uint16_t len;
+	uint16_t id;
+	uint32_t client_tag;
+	uint8_t payload[0];
+} __attribute__ ((packed)) sap_ste_message;
+
+/** sap_ste_connection - main admin structure that keeps data about connection
+ * with sim card.
+ */
+struct sap_ste_connection {
+	GIOChannel *io;
+	sap_ste_state_t state;
+	void *sap_data;
+};
+
+static struct sap_ste_connection *connection = NULL;
+
+/** sim2sap_result - Conversion table of sap result which varies with
+ * connection state and the message type.
+ */
+static const sap_result_t sim2sap_result[SAP_STE_MSG_MAX][SAP_STE_STATE_MAX] = {
+	/* SAP results for SEND APDU message */
+	{SAP_RESULT_ERROR_NOT_ACCESSIBLE,/*for SAP_STE_DISABLED state */
+	 SAP_RESULT_ERROR_POWERED_OFF,	/*for SAP_STE_POWERED_OFF state */
+	 SAP_RESULT_ERROR_CARD_REMOVED,	/*for SAP_STE_NO_CARD state */
+	 SAP_RESULT_ERROR_NO_REASON},	/*for SAP_STE_ENABLED state */
+	 /* SAP results for GET_ATR message */
+	{SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_POWERED_OFF,
+	 SAP_RESULT_ERROR_CARD_REMOVED,
+	 SAP_RESULT_ERROR_NO_REASON},
+	 /* SAP results POWER OFF message */
+	{SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_POWERED_OFF,
+	 SAP_RESULT_ERROR_CARD_REMOVED,
+	 SAP_RESULT_ERROR_NO_REASON},
+	 /* SAP results POWER ON message */
+	{SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_NOT_ACCESSIBLE,
+	 SAP_RESULT_ERROR_CARD_REMOVED,
+	 SAP_RESULT_ERROR_POWERED_ON},
+	 /* SAP results SIM RESET message */
+	{SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_POWERED_OFF,
+	 SAP_RESULT_ERROR_CARD_REMOVED,
+	 SAP_RESULT_ERROR_NOT_ACCESSIBLE},
+	 /* SAP results GET STATUS message */
+	{SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_NO_REASON,
+	 SAP_RESULT_ERROR_NO_REASON}
+	};
+
+static void connection_uninit(struct sap_ste_connection *conn);
+static int connection_watch(int sock, void *sap_data);
+
+/**
+ * get_sap_result - Convert STE sim status to sap result.
+ * @conn;	Connection info structure.
+ * @msg;	Sim message type.
+ * @status;	Sim status.
+ *
+ * Returns:
+ *	SAP result.
+ */
+static sap_result_t get_sap_result(struct sap_ste_connection *conn,
+				sap_ste_msg_t msg, sap_ste_status_t status)
+{
+	if (!conn)
+		return SAP_RESULT_ERROR_NO_REASON;
+
+	switch (status){
+		case SAP_STE_STATUS_OK:
+			return SAP_RESULT_OK;
+
+		case SAP_STE_STATUS_UNDEFINED_FAILURE:
+			return sim2sap_result[msg][conn->state];
+
+		default:
+			error("Cannot convert sap_ste_status [status: %d] \
+						to sap_result.", status);
+			return SAP_RESULT_ERROR_NO_REASON;
+	}
+}
+
+/**
+ * get_sap_reader_status - Convert STE sim reader status to sap reader result.
+ * @status;	Sim card reader status.
+ *
+ * Returns:
+ *	SAP reader status.
+ */
+static icc_reader_status_t get_sap_reader_status(sap_ste_card_status_t status)
+{
+	switch (status){
+		case SAP_STE_CARD_STATUS_UNKNOWN:
+			return ICC_READER_UNSPECIFIED_ERROR;
+
+		case SAP_STE_CARD_STATUS_NOT_ACTIVE:
+			return ICC_READER_NOT_PRESENT;
+
+		case SAP_STE_CARD_STATUS_ACTIVE:
+			return ICC_READER_CARD_POWERED_ON;
+
+		case SAP_STE_CARD_STATUS_INVALID:
+			return ICC_READER_CARD_POWERED_OFF;
+
+		case SAP_STE_CARD_STATUS_MISSING:
+			return ICC_READER_NO_CARD;
+
+		default:
+			error("Cannot convert sap_ste_reader_status [status: %d]\
+					to icc_sap_reader_status.", status);
+			return ICC_READER_UNSPECIFIED_ERROR;
+	}
+}
+
+/**
+ * sap_status_change - Convert STE sim card status to sap change event.
+ * @conn;	Connection info structure.
+ * @status;	Sim card status.
+ *
+ * This also updates Sim connection state.
+ *
+ * Returns:
+ *	SAP change event.
+ */
+static sap_status_change_t sap_status_change(struct sap_ste_connection *conn,
+					sap_ste_card_status_t status)
+{
+	if (!conn)
+		return SAP_STATUS_CHANGE_UNKNOWN_ERROR;
+
+	switch (status){
+		case SAP_STE_CARD_STATUS_UNKNOWN:
+			return SAP_STATUS_CHANGE_UNKNOWN_ERROR;
+
+		case SAP_STE_CARD_STATUS_ACTIVE:
+			conn->state = SAP_STE_ENABLED;
+			return SAP_STATUS_CHANGE_CARD_RESET;
+
+		case SAP_STE_CARD_STATUS_NOT_ACTIVE:
+			conn->state = SAP_STE_DISABLED;
+			return SAP_STATUS_CHANGE_CARD_NOT_ACCESSIBLE;
+
+		case SAP_STE_CARD_STATUS_MISSING:
+			conn->state = SAP_STE_DISABLED;
+			return SAP_STATUS_CHANGE_CARD_REMOVED;
+
+		case SAP_STE_CARD_STATUS_INVALID:
+			conn->state = SAP_STE_DISABLED;
+			return SAP_STATUS_CHANGE_CARD_NOT_ACCESSIBLE;
+
+		default:
+			error("Cannot convert sap_ste_status_change to \
+							sap_status_change.");
+			return SAP_STATUS_CHANGE_UNKNOWN_ERROR;
+	}
+}
+/**
+ * send_message - Send Sim message to Sim daemon.
+ * @conn;	Connection info structure.
+ * @buf;	Sim message.
+ * @size;	Size of Sim message
+ *
+ * Returns:
+ *	O if success or negaive integer if error occured.
+ */
+static int send_message(struct sap_ste_connection *conn,
+					sap_ste_message *buf, gsize size)
+{
+	gsize written = 0;
+	GIOError gerr;
+
+	DBG("[STE_DRV] send_message: conn %p, buf %p size %d", conn, buf,
+								(int) size);
+
+	gerr = g_io_channel_write(conn->io, (const gchar *) buf, size, &written);
+
+	if (written != size) {
+		error("[STE_DRV] send_message: written only %d bytes out of %d"
+						, (int)written, (int)size);
+		return -1;
+	}
+
+	if (gerr != G_IO_ERROR_NONE) {
+		int err = errno;
+		error("write error: %s(%d)", strerror(err), err);
+		return -err;
+	}
+
+	return 0;
+}
+
+/**
+ * sap_ste_start_sap_req - Create and send start SAP request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_start_sap_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_start_sap_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_START_SAP_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_end_sap_req - Create and send end SAP request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_end_sap_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_end_sap_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_END_SAP_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_end_sap_req - Create and send transfer apdu request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_send_apdu_req(struct sap_ste_connection *conn,
+						sap_parameter *param)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE + param->len;
+
+	DBG("[STE_DRV] sap_ste_send_apdu_req: conn %p param %p len %d",
+							conn, param, param->len);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_SEND_APDU_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+	memcpy(msg->payload, param->val, param->len);
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_get_atr_req - Create and send get ATR request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_get_atr_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_get_atr_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_GET_ATR_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_power_off_req - Create and send power off request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_power_off_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_power_off_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_POWER_OFF_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_power_on_req - Create and send power on request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_power_on_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_power_on_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_POWER_ON_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_reset_req - Create and send card reset request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_reset_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_reset_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_RESET_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_get_status_req - Create and send card status request message.
+ * @conn;	Connection info structure.
+ *
+ * Returns:
+ *	O if success or negaive integer in case of error.
+ */
+static int sap_ste_get_status_req(struct sap_ste_connection *conn)
+{
+	int err = 0;
+	sap_ste_message *msg = NULL;
+	gsize msg_size = SAP_STE_MSG_HEADER_SIZE;
+
+	DBG("[STE_DRV] sap_ste_get_status_req: conn %p", conn);
+
+	msg = (sap_ste_message *)g_malloc0(msg_size);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->len = msg_size - SAP_STE_MSG_LEN_SIZE;
+	msg->id = SAP_STE_GET_STATUS_REQ;
+	msg->client_tag = SAP_STE_CLIENT_TAG;
+
+	err = send_message(conn, msg, msg_size);
+
+	g_free(msg);
+	return err;
+}
+
+/**
+ * sap_ste_start_sap_rsp - Handle start SAP response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_start_sap_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	uint32_t *status;
+
+	DBG("[STE_DRV] sap_ste_start_sap_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+	if (msg && conn) {
+		status = (uint32_t*) msg->payload;
+		if (*status == SAP_STE_STATUS_OK)
+			sap_connect_rsp(conn->sap_data, SAP_STATUS_OK, 0);
+		else {
+			sap_connect_rsp(conn->sap_data, SAP_STATUS_CONNECTION_FAILED, 0);
+			connection_uninit(conn);
+		}
+	}
+}
+
+/**
+ * sap_ste_end_sap_rsp - Handle end SAP response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_end_sap_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	DBG("[STE_DRV] sap_ste_end_sap_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+	if (msg && conn) {
+		sap_disconnect_rsp(conn->sap_data);
+		connection_uninit(conn);
+	}
+}
+
+/**
+ * sap_ste_send_apdu_rsp - Handle transfer apdu response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void  sap_ste_send_apdu_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	uint32_t *status;
+	sap_result_t sr;
+	uint8_t *apdu = NULL;
+	uint16_t len = 0;
+
+	DBG("[STE_DRV] sap_ste_send_apdu_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t*) msg->payload;
+		if (*status == SAP_STE_STATUS_OK) {
+			apdu = (uint8_t *)(msg->payload + SAP_STE_MSG_STATUS_SIZE);
+			len = msg->len - (SAP_STE_MSG_HEADER_SIZE) +
+				SAP_STE_MSG_LEN_SIZE - SAP_STE_MSG_STATUS_SIZE;
+		}
+
+		sr = get_sap_result(conn, SAP_STE_SEND_APDU_MSG, *status);
+		sap_transfer_apdu_rsp(conn->sap_data, sr, apdu, len);
+	}
+}
+
+/**
+ * sap_ste_get_atr_rsp - Handle get ATR response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_get_atr_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	uint32_t *status;
+	sap_result_t sr;
+	uint8_t *atr = NULL;
+	uint16_t len = 0;
+
+	DBG("[STE_DRV] sap_ste_get_atr_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t*) msg->payload;
+		if (*status == SAP_STE_STATUS_OK) {
+			atr = (uint8_t *)(msg->payload + SAP_STE_MSG_STATUS_SIZE);
+			len = msg->len - (SAP_STE_MSG_HEADER_SIZE) +
+							SAP_STE_MSG_LEN_SIZE;
+		}
+
+		sr = get_sap_result(conn, SAP_STE_GET_ATR_MSG, *status);
+		sap_transfer_atr_rsp(conn->sap_data, sr, atr, len);
+	}
+}
+
+/**
+ * sap_ste_power_off_rsp - Handle power off response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_power_off_rsp(struct sap_ste_connection *conn,
+							sap_ste_message * msg)
+{
+	uint32_t *status;
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_ste_power_off_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t *) msg->payload;
+		if (*status == SAP_STE_STATUS_OK)
+			conn->state = SAP_STE_POWERED_OFF;
+
+		sr = get_sap_result(conn, SAP_STE_POWER_OFF_MSG, *status);
+		sap_power_sim_off_rsp(conn->sap_data, sr);
+	}
+}
+
+/**
+ * sap_ste_power_on_rsp - Handle power on response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_power_on_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	uint32_t *status;
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_ste_power_on_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t *) msg->payload;
+		if (*status == SAP_STE_STATUS_OK)
+			conn->state = SAP_STE_ENABLED;
+
+		sr = get_sap_result(conn, SAP_STE_POWER_ON_MSG, *status);
+		sap_power_sim_on_rsp(conn->sap_data, sr);
+	}
+}
+
+/**
+ * sap_ste_reset_rsp - Handle reset response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_reset_rsp(struct sap_ste_connection *conn,
+					sap_ste_message * msg)
+{
+	uint32_t *status;
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_ste_reset_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t *) msg->payload;
+		if (*status == SAP_STE_STATUS_OK)
+			conn->state = SAP_STE_ENABLED;
+
+		sr = get_sap_result(conn, SAP_STE_RESET_MSG, *status);
+		sap_reset_sim_rsp(conn->sap_data, sr);
+	}
+}
+
+/**
+ * sap_ste_get_status_rsp - Handle card status response message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_get_status_rsp(struct sap_ste_connection *conn,
+						sap_ste_message * msg)
+{
+	uint8_t *p = NULL;
+	uint32_t *status;
+	sap_result_t sr;
+	sap_ste_card_status_t cs;
+	icc_reader_status_t iccrs;
+
+	DBG("[STE_DRV] sap_ste_get_status_rsp: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		p = msg->payload;
+		status = (uint32_t *)p; p += sizeof(uint32_t);
+		cs = *((uint16_t *)p);
+
+		iccrs = get_sap_reader_status(cs);
+		sr = get_sap_result(conn, SAP_STE_GET_STATUS_MSG, *status);
+		sap_transfer_card_reader_status_rsp(conn->sap_data, sr, iccrs);
+	}
+}
+
+/**
+ * sap_ste_status_ind - Handle status indication message.
+ * @conn;	Connection info structure.
+ * @msg;	Response message.
+ */
+static void sap_ste_status_ind(struct sap_ste_connection *conn,
+							sap_ste_message * msg)
+{
+	sap_status_change_t sc;
+	sap_ste_card_status_t cs;
+	uint32_t *status;
+
+	DBG("[STE_DRV] sap_ste_status_ind: conn %p (conn %p) msg %p",
+							conn, connection, msg );
+
+	if (msg && conn) {
+		status = (uint32_t *) msg->payload;
+		cs = *status;
+		sc = sap_status_change(conn, cs);
+
+		sap_status_ind(conn->sap_data, sc);
+	}
+}
+
+/**
+ * handle_msg - Handle messages from Sim daemon.
+ * @conn;	Connection info structure.
+ * @buf;	Data buffer.
+ * @size;	Size of data buffer.
+ *
+ * Returns:
+ *    0 if success or EBADMSG in case of bad message format.
+ */
+static int handle_msg(struct sap_ste_connection *conn, unsigned char *buf,
+								gsize size)
+{
+	unsigned char *iter = buf;
+	sap_ste_message * msg = (sap_ste_message *) buf;
+	gssize msize = (gssize) size;
+
+	DBG("[STE_DRV] handle_msg: msg %p conn %p", msg, conn);
+
+	if (msg == NULL || conn == NULL)
+		return -EFAULT;
+
+	do {
+		DBG("[STE_DRV] handle_msg: msize %d msg->len %d.",
+							(int)msize, msg->len);
+
+		/* Message must be at least size of header len */
+		if (msize < SAP_STE_MSG_HEADER_SIZE) {
+			error("[STE_DRV] Invalid message size.");
+			return -EBADMSG;
+		}
+
+		/* Message must be completed. */
+		if (msize < (SAP_STE_MSG_LEN_SIZE + msg->len)) {
+			error("[STE_DRV] Not complete message.");
+			return -EBADMSG;
+		}
+
+		switch (msg->id){
+			case SAP_STE_START_SAP_RSP:
+				sap_ste_start_sap_rsp(conn, msg);
+				break;
+
+			case SAP_STE_END_SAP_RSP:
+				sap_ste_end_sap_rsp(conn, msg);
+				break;
+
+			case SAP_STE_SEND_APDU_RSP:
+				sap_ste_send_apdu_rsp(conn, msg);
+				break;
+
+			case SAP_STE_GET_ATR_RSP:
+				sap_ste_get_atr_rsp(conn, msg);
+				break;
+
+			case SAP_STE_POWER_OFF_RSP:
+				sap_ste_power_off_rsp(conn, msg);
+				break;
+
+			case SAP_STE_POWER_ON_RSP:
+				sap_ste_power_on_rsp(conn, msg);
+				break;
+
+			case SAP_STE_RESET_RSP:
+				sap_ste_reset_rsp(conn, msg);
+				break;
+
+			case SAP_STE_GET_STATUS_RSP:
+				sap_ste_get_status_rsp(conn, msg);
+				break;
+
+			case SAP_STE_STATUS_IND:
+				sap_ste_status_ind(conn, msg);
+				break;
+
+			default:
+				error("[STE_DRV] Invalid or not supported \
+						frame [0x%02x].", msg->id);
+		}
+
+		/* Reduce total buffer size of just handled frame size*/
+		msize -= (SAP_STE_MSG_HEADER_SIZE +
+				(msg->len - (SAP_STE_MSG_HEADER_SIZE) +
+				 SAP_STE_MSG_LEN_SIZE));
+
+		/* Move msg ponter to then next message if any */
+		iter += (msg->len + SAP_STE_MSG_LEN_SIZE);
+		msg = (sap_ste_message *)iter;
+	} while (msize > 0);
+
+	return 0;
+}
+
+/**
+ * connection_io_data_cb - Handle data on socket to Sim daemon.
+ * @io;		Connection info structure.
+ * @conn;	Conndition that triggered this callback.
+ * @data;	Data buffor.
+ *
+ * Returns:
+ *    True if @data was handled, False otherwise.
+ */
+static gboolean connection_io_data_cb(GIOChannel *io, GIOCondition cond,
+							gpointer data)
+{
+	GIOError err = G_IO_ERROR_NONE;
+	unsigned char buf[SAP_STE_MAX_MSG_SIZE];
+	gsize read_bytes = 0;
+
+	if (cond & G_IO_NVAL) {
+		DBG("[STE_DRV] NVAL on sim socket");
+		return FALSE;
+	}
+
+	if (cond & G_IO_HUP) {
+		DBG("[STE_DRV] HUP on sim socket");
+		return FALSE;
+	}
+
+	if (cond & G_IO_ERR) {
+		DBG("[STE_DRV] ERR on sim socket");
+		return FALSE;
+	}
+
+	err = g_io_channel_read(io, (gchar *)buf, sizeof(buf), &read_bytes);
+	if (err != G_IO_ERROR_NONE) {
+		error("[STE_DRV] Error while reading from channel \
+						[err 0x%x io %p].", err, io);
+		return FALSE;
+	}
+
+	if (handle_msg(data, buf, read_bytes) < 0)
+		error("[STE_DRV] Invalid STE Sim message.");
+
+	return TRUE;
+}
+
+/**
+ * connection_io_destroy_cb - Clean up the SAP serer in case of socket closure.
+ * @data;	Private data.
+ *
+ * The callback is run if the connection with Sim daemon has been lost.
+ */
+static void connection_io_destroy_cb(void *data)
+{
+	struct sap_ste_connection *conn = (struct sap_ste_connection *)data;
+
+	if (conn && connection) {
+		DBG("[STE_DRV] connection_io_destroy_cb: conn %p conn %p io %p",
+						conn, connection, conn->io);
+
+		g_io_channel_unref(conn->io);
+		g_io_channel_shutdown(conn->io, TRUE, NULL);
+		g_free(conn);
+		connection = NULL;
+	}
+}
+
+/**
+ * connection_init - Initialize connection with Sim Daemon.
+ * @sap_data;	Private data of SAP Server.
+ *
+ * Returns:
+ *    0 if success, negative number in case of an error.
+ */
+static int connection_init(void * sap_data)
+{
+	int sock;
+	int len = 0;
+	struct sockaddr_un addr;
+	ssize_t addr_len;
+
+	/* Create a socket to communicate with SIMD*/
+	sock = socket(PF_UNIX, SOCK_STREAM, 0);
+	if (sock < 0) {
+		error("[STE_DRV] Create socket failed: %s", strerror(errno));
+		return -errno;
+	}
+
+	/*Connect to SIMD*/
+	memset(&addr, 0, sizeof(addr));
+	addr.sun_family = AF_UNIX;
+	len = sprintf(addr.sun_path, SAP_STE_UNIX_SOCKET_NAME);
+	addr_len = sizeof(addr.sun_family) + len;
+	if (connect(sock, (struct sockaddr *) &addr, addr_len) < 0) {
+		error("[STE_DRV] Connect to the socket failed:  %s",
+							strerror(errno));
+		goto drop;
+	}
+
+	if (fcntl(sock, F_SETFL, O_NONBLOCK) > 0) {
+		error("[STE_DRV] fcntl() failed: %s", strerror(errno));
+		goto drop;
+	}
+
+	DBG("[STE_DRV] connection_init: sock %d ",sock);
+
+	/* Start watching incoming data */
+	if (connection_watch(sock, sap_data) < 0)
+		goto drop;
+
+	return 0;
+
+drop:
+	DBG("[STE_DRV] connection_init: drop!");
+	close(sock);
+	return -errno;
+}
+
+/**
+ * connection_uninit - Disconnect from Sim daemon.
+ * @conn;	Connection info structure.
+ */
+static void connection_uninit(struct sap_ste_connection *conn)
+{
+	DBG("[STE_DRV] connection_uninit: conn %p connection %p", conn,
+								connection);
+
+	if (!conn)
+		return;
+
+	g_io_channel_shutdown(conn->io, TRUE, NULL);
+	g_io_channel_unref(conn->io);
+	g_free(conn);
+
+	connection = NULL;
+}
+
+
+/**
+ * connection_watch - Start watching Sim daemon connection.
+ * @sap_data;	Private data of SAP Server.
+ *
+ * Returns:
+ *    0 if success, negative number in case of an error.
+ */
+static int connection_watch(int sock, void *sap_data)
+{
+	GIOChannel *io = NULL;
+
+	DBG("[STE_DRV] connection_watch: sock %d, sap_data %p ", sock,
+								sap_data);
+
+	if (sock < 0)
+		return -1;
+
+	io = g_io_channel_unix_new(sock);
+	g_io_channel_set_close_on_unref(io, TRUE);
+
+
+	connection = g_new0(struct sap_ste_connection, 1);
+	if (!connection) {
+		error("[STE_DRV] connection_watch: connection %p io %p",
+								connection, io);
+		g_io_channel_shutdown(io, TRUE, NULL);
+		g_io_channel_unref(io);
+		return -1;
+	}
+
+	connection->io = io;
+	connection->sap_data = sap_data;
+	connection->state = SAP_STE_DISABLED;
+
+	g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
+			G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+			connection_io_data_cb, connection, connection_io_destroy_cb);
+
+	return 0;
+}
+
+/**
+ * sap_connect_req - Handle SAP connect request.
+ * @sap_data;	Private data of SAP Server.
+ * @maxmsgsize;	Message size supported by the SAP client.
+ */
+void sap_connect_req(void *sap_device, uint16_t maxmsgsize)
+{
+
+	DBG("[STE_DRV] sap_connect_req: conn %p sap_device %p maxmsgsize %d",
+			connection, sap_device, maxmsgsize);
+
+	if (maxmsgsize < SAP_STE_MIN_MSG_SIZE) {
+		sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL,
+							SAP_STE_MAX_MSG_SIZE);
+		return;
+	}
+
+	if (maxmsgsize > SAP_STE_MAX_MSG_SIZE) {
+		sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED,
+							SAP_STE_MAX_MSG_SIZE);
+		return;
+	}
+
+	if (connection_init(sap_device) < 0) {
+		DBG("[STE_DRV] connection_init: failed!");
+		sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED, 0);
+		return;
+	}
+
+	if (connection && connection->state == SAP_STE_DISABLED) {
+		if (sap_ste_start_sap_req(connection) < 0) {
+			sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED,
+							SAP_STE_MAX_MSG_SIZE);
+			connection_uninit(connection);
+		}
+	} else {
+		DBG("[STE_DRV] Connection failed! (connection %p) ", connection);
+		sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED, 0);
+	}
+}
+
+/**
+ * sap_disconnect_req - Handle SAP disconnect request.
+ * @sap_data;	Private data of SAP Server.
+ * @linkloss;	Indicates thet link is being disconnected due to link loss.
+ */
+void sap_disconnect_req(void *sap_device, uint8_t linkloss)
+{
+	DBG("[STE_DRV] sap_disconnect_req: conn %p sap_device %p linkloss %d",
+					connection, sap_device, linkloss);
+	if (connection && linkloss) {
+		connection_uninit(connection);
+		return;
+	}
+
+	if (connection && connection->state != SAP_STE_DISABLED) {
+		if (sap_ste_end_sap_req(connection) < 0) {
+			sap_disconnect_rsp(sap_device);
+		}
+	} else {
+		sap_disconnect_rsp(sap_device);
+	}
+}
+
+/**
+ * sap_transfer_apdu_req - Handle SAP transfer apdu request.
+ * @sap_data;	Private data of SAP Server.
+ * @param;	SAP parameter of the request.
+ */
+void sap_transfer_apdu_req(void *sap_device, sap_parameter *param)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_transfer_apdu_req: conn %p sap_device %p param %p\
+		param len %d", connection, sap_device, param, param->len);
+
+	if (connection && connection->state == SAP_STE_ENABLED) {
+		if (sap_ste_send_apdu_req(connection, param) < 0)
+			sap_transfer_apdu_rsp(sap_device,
+					SAP_RESULT_ERROR_NO_REASON, NULL, 0);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_SEND_APDU_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_transfer_apdu_rsp(sap_device, sr, NULL, 0);
+	}
+}
+
+/**
+ * sap_transfer_atr_req - Handle SAP ATR request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_transfer_atr_req(void * sap_device)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_transfer_atr_req: conn %p, sap_device %p",
+							connection, sap_device);
+
+	if (connection && connection->state == SAP_STE_ENABLED) {
+		if (sap_ste_get_atr_req(connection) < 0)
+			sap_transfer_atr_rsp(sap_device,
+				SAP_RESULT_ERROR_NO_DATA, NULL, 0);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_GET_ATR_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_transfer_atr_rsp(sap_device, sr, NULL, 0);
+	}
+}
+
+/**
+ * sap_power_sim_off_req - Handle SAP power off request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_power_sim_off_req(void *sap_device)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_power_sim_off_req: conn %p, sap_device %p",
+							connection, sap_device);
+
+	if (connection && connection->state == SAP_STE_ENABLED) {
+		if (sap_ste_power_off_req(connection) < 0)
+			sap_power_sim_off_rsp(sap_device,
+					SAP_RESULT_ERROR_NO_REASON);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_POWER_OFF_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_power_sim_off_rsp(sap_device, sr);
+	}
+}
+
+/**
+ * sap_power_sim_on_req - Handle SAP power on request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_power_sim_on_req(void *sap_device)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_power_sim_on_req: conn %p, sap_device %p",
+							connection, sap_device);
+
+	if (connection && connection->state == SAP_STE_POWERED_OFF) {
+		if (sap_ste_power_on_req(connection) < 0)
+			sap_power_sim_on_rsp(sap_device,
+					SAP_RESULT_ERROR_NO_REASON);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_POWER_ON_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_power_sim_on_rsp(sap_device, sr);
+	}
+}
+
+/**
+ * sap_reset_sim_req - Handle SAP reset request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_reset_sim_req(void *sap_device)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_reset_sim_req: conn %p, sap_device %p",
+							connection, sap_device);
+
+	if (connection && connection->state == SAP_STE_ENABLED) {
+		if (sap_ste_reset_req(connection) < 0)
+			sap_reset_sim_rsp(sap_device,
+						SAP_RESULT_ERROR_NO_REASON);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_RESET_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_reset_sim_rsp(sap_device, sr);
+	}
+}
+
+/**
+ * sap_transfer_card_reader_status_req - Handle get card reader status request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_transfer_card_reader_status_req(void * sap_device)
+{
+	sap_result_t sr;
+
+	DBG("[STE_DRV] sap_transfer_card_reader_status_req: conn %p, \
+					sap_device %p", connection, sap_device);
+
+	if (connection && connection->state != SAP_STE_DISABLED) {
+		if (sap_ste_get_status_req(connection) < 0)
+			sap_transfer_card_reader_status_rsp(sap_device,
+						SAP_RESULT_ERROR_NO_DATA,
+						ICC_READER_UNSPECIFIED_ERROR);
+	} else {
+		sr = get_sap_result(connection, SAP_STE_GET_STATUS_MSG,
+					SAP_STE_STATUS_UNDEFINED_FAILURE);
+		sap_transfer_card_reader_status_rsp(sap_device, sr,
+						ICC_READER_UNSPECIFIED_ERROR);
+	}
+}
+
+/**
+ * sap_set_transport_protocol_req - Handle set transport protocol request.
+ * @sap_data;	Private data of SAP Server.
+ */
+void sap_set_transport_protocol_req(void * sap_device,sap_parameter * param)
+{
+	sap_transport_protocol_rsp(sap_device, SAP_RESULT_NOT_SUPPORTED);
+}
+
+int sap_init(void)
+{
+	return 0;
+}
+
+void sap_exit(void)
+{
+}
diff --git a/sap/sap.h b/sap/sap.h
new file mode 100644
index 0000000..a9189fc
--- /dev/null
+++ b/sap/sap.h
@@ -0,0 +1,187 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 ST-Ericsson SA
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  Author: Marek Skowron <marek.skowron@tieto.com> for ST-Ericsson.
+ *  Author: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> for ST-Ericsson.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdint.h>
+#include <glib.h>
+
+ #define SAP_VERSION 0x0101
+
+/* Connection Status - SAP v1.1 section 5.2.2 */
+typedef enum {
+	SAP_STATUS_OK 				= 0x00,
+	SAP_STATUS_CONNECTION_FAILED		= 0x01,
+	SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED	= 0x02,
+	SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL	= 0x03,
+	SAP_STATUS_OK_ONGOING_CALL		= 0x04
+} sap_status_t;
+
+/* Disconnection Type - SAP v1.1 section 5.2.3 */
+typedef enum {
+	SAP_DISCONNECTION_TYPE_GRACEFUL  = 0x00,
+	SAP_DISCONNECTION_TYPE_IMMEDIATE = 0x01,
+	SAP_DISCONNECTION_TYPE_CLIENT    = 0xFF
+} sap_disconnection_type_t;
+
+/* Result codes - SAP v1.1 section 5.2.4 */
+typedef enum {
+	SAP_RESULT_OK 			= 0x00,
+	SAP_RESULT_ERROR_NO_REASON	= 0x01,
+	SAP_RESULT_ERROR_NOT_ACCESSIBLE	= 0x02,
+	SAP_RESULT_ERROR_POWERED_OFF	= 0x03,
+	SAP_RESULT_ERROR_CARD_REMOVED	= 0x04,
+	SAP_RESULT_ERROR_POWERED_ON	= 0x05,
+	SAP_RESULT_ERROR_NO_DATA	= 0x06,
+	SAP_RESULT_NOT_SUPPORTED	= 0x07
+} sap_result_t;
+
+/* Status Change - SAP v1.1 section 5.2.8 */
+typedef enum {
+	SAP_STATUS_CHANGE_UNKNOWN_ERROR	= 0x00,
+	SAP_STATUS_CHANGE_CARD_RESET	= 0x01,
+	SAP_STATUS_CHANGE_CARD_NOT_ACCESSIBLE = 0x02,
+	SAP_STATUS_CHANGE_CARD_REMOVED	= 0x03,
+	SAP_STATUS_CHANGE_CARD_INSERTED	= 0x04,
+	SAP_STATUS_CHANGE_CARD_RECOVERED = 0x05
+} sap_status_change_t;
+
+/* Message format - SAP v1.1 section 5.1 */
+typedef struct {
+	uint8_t id;
+	uint8_t reserved;
+	uint16_t len;
+	uint8_t val[0];
+	/*
+	 * Padding bytes 0-3 bytes
+	 */
+} __attribute__ ((packed)) sap_parameter;
+
+typedef struct {
+	uint8_t id;
+	uint8_t nparam;
+	uint16_t reserved;
+	sap_parameter param[0];
+} __attribute__ ((packed)) sap_message;
+
+
+typedef enum {
+	ICC_READER_UNSPECIFIED_ERROR, /* No further information available */
+	ICC_READER_NOT_PRESENT,       /* Card Reader removed or not present */
+	ICC_READER_BUSY,              /* Card Reader in use */
+	ICC_READER_CARD_POWERED_ON,   /* Card in reader and is powered on */
+	ICC_READER_DEACTIVATED,       /* Card Reader deactivated */
+	ICC_READER_CARD_POWERED_OFF,  /* Card in reader, but powered off */
+	ICC_READER_NO_CARD,           /* No card in reader */
+	ICC_READER_LAST
+} icc_reader_status_t;
+
+
+#define SAP_BUF_SIZE		512
+
+#define SAP_MSG_HEADER_SIZE	4
+
+typedef enum {
+	SAP_CONNECT_REQ		= 0x00,
+	SAP_CONNECT_RESP	= 0x01,
+	SAP_DISCONNECT_REQ	= 0x02,
+	SAP_DISCONNECT_RESP	= 0x03,
+	SAP_DISCONNECT_IND	= 0x04,
+	SAP_TRANSFER_APDU_REQ	= 0x05,
+	SAP_TRANSFER_APDU_RESP	= 0x06,
+	SAP_TRANSFER_ATR_REQ	= 0x07,
+	SAP_TRANSFER_ATR_RESP	= 0x08,
+	SAP_POWER_SIM_OFF_REQ	= 0x09,
+	SAP_POWER_SIM_OFF_RESP	= 0x0A,
+	SAP_POWER_SIM_ON_REQ	= 0x0B,
+	SAP_POWER_SIM_ON_RESP	= 0x0C,
+	SAP_RESET_SIM_REQ	= 0x0D,
+	SAP_RESET_SIM_RESP	= 0x0E,
+	SAP_TRANSFER_CARD_READER_STATUS_REQ	= 0x0F,
+	SAP_TRANSFER_CARD_READER_STATUS_RESP	= 0x10,
+	SAP_STATUS_IND	= 0x11,
+	SAP_ERROR_RESP	= 0x12,
+	SAP_SET_TRANSPORT_PROTOCOL_REQ	= 0x13,
+	SAP_SET_TRANSPORT_PROTOCOL_RESP	= 0x14,
+} sap_protocol;
+
+/* Parameters Ids - SAP 1.1 section 5.2 */
+#define SAP_PARAM_ID_MAX_MSG_SIZE             0x00
+#define SAP_PARAM_ID_MAX_MSG_SIZE_LEN         0x02
+
+#define SAP_PARAM_ID_CONN_STATUS            0x01
+#define SAP_PARAM_ID_CONN_STATUS_LEN        0x01
+
+#define SAP_PARAM_ID_RESULT_CODE            0x02
+#define SAP_PARAM_ID_RESULT_CODE_LEN        0x01
+
+#define SAP_PARAM_ID_DISCONNECT_IND         0x03
+#define SAP_PARAM_ID_DISCONNECT_IND_LEN     0x01
+
+#define SAP_PARAM_ID_COMMAND_APDU           0x04
+#define SAP_PARAM_ID_RESPONSE_APDU          0x05
+#define SAP_PARAM_ID_ATR                    0x06
+
+#define SAP_PARAM_ID_CARD_READER_STATUS     0x07
+#define SAP_PARAM_ID_CARD_READER_STATUS_LEN 0x01
+
+#define SAP_PARAM_ID_STATUS_CHANGE          0x08
+#define SAP_PARAM_ID_STATUS_CHANGE_LEN      0x01
+
+#define SAP_PARAM_ID_TRANSPORT_PROTOCOL     0x09
+#define SAP_PARAM_ID_TRANSPORT_PROTOCOL_LEN 0x01
+
+#define SAP_PARAM_ID_COMMAND_APDU7816       0x10
+
+/* Transport Protocol - SAP v1.1 section 5.2.9 */
+#define SAP_TRANSPORT_PROTOCOL_T0           0x00
+#define SAP_TRANSPORT_PROTOCOL_T1           0x01
+
+/*SAP driver init and exit routines. Implemented by sap-*.c */
+int sap_init(void);
+void sap_exit(void);
+
+/* SAP requests implemented by sap-*.c */
+void sap_connect_req(void *sap_device, uint16_t maxmsgsize);
+void sap_disconnect_req(void *sap_device, uint8_t linkloss);
+void sap_transfer_apdu_req(void *sap_device, sap_parameter *param);
+void sap_transfer_atr_req(void *sap_device);
+void sap_power_sim_off_req(void *sap_device);
+void sap_power_sim_on_req(void *sap_device);
+void sap_reset_sim_req(void *sap_device);
+void sap_transfer_card_reader_status_req(void *sap_device);
+void sap_set_transport_protocol_req(void *sap_device, sap_parameter *param);
+
+/*SAP responses to SAP requests. Implemented by server.c */
+int sap_connect_rsp(void *sap_device, sap_status_t status, uint16_t maxmsgsize);
+int sap_disconnect_rsp(void *sap_device);
+int sap_transfer_apdu_rsp(void *sap_device, sap_result_t result, uint8_t *sap_apdu_resp, uint16_t length);
+int sap_transfer_atr_rsp(void *sap_device, sap_result_t result, uint8_t *sap_atr, uint16_t length);
+int sap_power_sim_off_rsp(void *sap_device, sap_result_t result);
+int sap_power_sim_on_rsp(void *sap_device, sap_result_t result);
+int sap_reset_sim_rsp(void *sap_device, sap_result_t result);
+int sap_transfer_card_reader_status_rsp(void *sap_device, sap_result_t result, icc_reader_status_t status);
+int sap_error_rsp(void *sap_device);
+int sap_transport_protocol_rsp(void *sap_device, sap_result_t result);
+
+/* Event indication. Implemented by server.c*/
+int sap_status_ind(void *sap_device, sap_status_change_t status_change);
+
diff --git a/sap/server.c b/sap/server.c
new file mode 100644
index 0000000..683df5e
--- /dev/null
+++ b/sap/server.c
@@ -0,0 +1,1516 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 ST-Ericsson SA
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  Author: Marek Skowron <marek.skowron@tieto.com> for ST-Ericsson.
+ *  Author: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> for ST-Ericsson.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <glib.h>
+#include <gdbus.h>
+#include <netinet/in.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
+
+#include "adapter.h"
+#include "btio.h"
+#include "sdpd.h"
+#include "log.h"
+#include "error.h"
+#include "dbus-common.h"
+
+#include "sap.h"
+#include "server.h"
+
+#define SAP_SERVER_INTERFACE	"org.bluez.SimAccess"
+#define SAP_UUID		"0000112D-0000-1000-8000-00805F9B34FB"
+#define SAP_SERVER_CHANNEL	8
+#define SAP_BUF_SIZE		512
+
+#define PADDING4(x) (4 - (x & 0x03))
+#define PARAMETER_SIZE(x) (sizeof(sap_parameter) + x + PADDING4(x))
+
+#define SAP_NO_REQ 0xFF
+
+#define SAP_TIMER_GRACEFUL_DISCONNECT 30
+#define SAP_TIMER_NO_ACTIVITY 30
+
+typedef enum {
+	SAP_STATE_DISCONNECTED,
+	SAP_STATE_CONNECT_IN_PROGRESS,
+	SAP_STATE_CONNECTED,
+	SAP_STATE_GRACEFUL_DISCONNECT,
+	SAP_STATE_IMMEDIATE_DISCONNECT,
+	SAP_STATE_CLIENT_DISCONNECT
+} sap_state_t;
+
+struct sap_server {
+	bdaddr_t src;
+	char *path;
+	gboolean enable;
+	uint32_t record_id;
+	GIOChannel *listen_io;
+	GIOChannel *io;  /* Connected client channel.*/
+	sap_state_t state;
+	uint8_t processing_req;
+	guint timer_id;
+};
+
+static DBusConnection *connection = NULL;
+
+static void connect_req(void *data, sap_parameter *param);
+static int disconnect_req(void *data, sap_disconnection_type_t disc_type);
+static void transfer_apdu_req(void *data, sap_parameter *param);
+static void transfer_atr_req(void *data);
+static void power_sim_off_req(void *data);
+static void power_sim_on_req(void *data);
+static void reset_sim_req(void *data);
+static void transfer_card_reader_status_req(void *data);
+static void set_transport_protocol_req(void *data, sap_parameter *param);
+static int disconnect_ind(void *sap_device, sap_disconnection_type_t type);
+
+static gsize add_result_parameter(sap_result_t result, sap_parameter *param);
+
+static int is_power_sim_off_req_allowed(uint8_t processing_req);
+static int is_reset_sim_req_allowed(uint8_t processing_req);
+
+static int check_msg(sap_message *msg);
+
+static void start_guard_timer(struct sap_server *server, guint interval);
+static void stop_guard_timer(struct sap_server *server);
+static gboolean guard_timeout(gpointer data);
+
+static gsize add_result_parameter(sap_result_t result, sap_parameter *param)
+{
+	param->id = SAP_PARAM_ID_RESULT_CODE;
+	param->len = htons(SAP_PARAM_ID_RESULT_CODE_LEN);
+	*param->val = (uint8_t) result;
+	return PARAMETER_SIZE(SAP_PARAM_ID_RESULT_CODE_LEN);
+}
+
+
+static inline int is_power_sim_off_req_allowed(uint8_t processing_req)
+{
+	switch(processing_req) {
+	case SAP_NO_REQ:
+	case SAP_TRANSFER_APDU_REQ:
+	case SAP_TRANSFER_ATR_REQ:
+	case SAP_POWER_SIM_ON_REQ:
+	case SAP_RESET_SIM_REQ:
+	case SAP_TRANSFER_CARD_READER_STATUS_REQ:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static inline int is_reset_sim_req_allowed(uint8_t processing_req)
+{
+	switch(processing_req) {
+	case SAP_NO_REQ:
+	case SAP_TRANSFER_APDU_REQ:
+	case SAP_TRANSFER_ATR_REQ:
+	case SAP_TRANSFER_CARD_READER_STATUS_REQ:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static int check_msg(sap_message *msg)
+{
+	if(!msg)
+		return -EFAULT;
+
+	switch(msg->id) {
+	case SAP_CONNECT_REQ:
+		if (msg->nparam == 0x01 &&
+				msg->param->id == SAP_PARAM_ID_MAX_MSG_SIZE &&
+				ntohs(msg->param->len) == SAP_PARAM_ID_MAX_MSG_SIZE_LEN)
+			return 0;
+		break;
+	case SAP_TRANSFER_APDU_REQ:
+		if (msg->nparam == 0x01 &&
+				(msg->param->id == SAP_PARAM_ID_COMMAND_APDU ||
+				msg->param->id == SAP_PARAM_ID_COMMAND_APDU7816) &&
+				msg->param->len != 0x00)
+			return 0;
+		break;
+	case SAP_SET_TRANSPORT_PROTOCOL_REQ:
+		if (msg->nparam == 0x01 &&
+				msg->param->id == SAP_PARAM_ID_TRANSPORT_PROTOCOL &&
+				ntohs(msg->param->len) == SAP_PARAM_ID_TRANSPORT_PROTOCOL_LEN &&
+				(*msg->param->val  == SAP_TRANSPORT_PROTOCOL_T0 ||
+				*msg->param->val == SAP_TRANSPORT_PROTOCOL_T1))
+			return 0;
+		break;
+	case SAP_DISCONNECT_REQ:
+	case SAP_TRANSFER_ATR_REQ:
+	case SAP_POWER_SIM_OFF_REQ:
+	case SAP_POWER_SIM_ON_REQ:
+	case SAP_RESET_SIM_REQ:
+	case SAP_TRANSFER_CARD_READER_STATUS_REQ:
+		if (msg->nparam == 0x00)
+			return 0;
+		break;
+	}
+
+	error("Invalid message");
+	return -EBADMSG;
+}
+
+
+static void start_guard_timer(struct sap_server *server, guint interval)
+{
+	if(!server)
+		return;
+
+	if (!server->timer_id)
+		server->timer_id = g_timeout_add_seconds(interval,
+							guard_timeout, server);
+	else
+		error("Timer is already active.");
+}
+
+static void stop_guard_timer(struct sap_server *server)
+{
+	if (server && server->timer_id) {
+		g_source_remove(server->timer_id);
+		server->timer_id = 0;
+	}
+}
+
+static gboolean guard_timeout(gpointer data)
+{
+	struct sap_server *server = data;
+
+	if (!server)
+		return FALSE;
+
+	DBG("guard_timeout: state: %x pr %x", server->state,
+					server->processing_req);
+
+	server->timer_id = 0;
+
+	switch(server->state) {
+	case SAP_STATE_DISCONNECTED:
+		/* Client opened RFCOMM channel but didn't send CONNECT_REQ,
+		 * in fixed time or client disconnected SAP connection but
+		 * didn't closed RFCOMM channel in fixed time.*/
+		if (server->io)
+			g_io_channel_shutdown(server->io, TRUE, NULL);
+		break;
+	case SAP_STATE_GRACEFUL_DISCONNECT:
+		/* Client didn't disconnect SAP connection in fixed time,
+		 * so close SAP connection immediately. */
+		disconnect_req(server, SAP_DISCONNECTION_TYPE_IMMEDIATE);
+		break;
+	default:
+		error("guard_timeout: Unexpected state.");
+		break;
+	}
+
+	return FALSE;
+}
+
+static sdp_record_t *create_sap_record(uint8_t channel)
+{
+	sdp_list_t *apseq, *aproto, *profiles, *proto[2], *root, *svclass_id;
+	uuid_t sap_uuid, gt_uuid, root_uuid, l2cap, rfcomm;
+	sdp_profile_desc_t profile;
+	sdp_record_t *record;
+	sdp_data_t *ch;
+
+	record = sdp_record_alloc();
+	if (!record)
+		return NULL;
+
+	root = sdp_list_append(NULL, &root_uuid);
+	sdp_set_browse_groups(record, root);
+	sdp_list_free(root, NULL);
+
+	sdp_uuid16_create(&sap_uuid, SAP_SVCLASS_ID);
+	svclass_id = sdp_list_append(NULL, &sap_uuid);
+	sdp_uuid16_create(&gt_uuid, GENERIC_TELEPHONY_SVCLASS_ID);
+	svclass_id = sdp_list_append(svclass_id, &gt_uuid);
+
+	sdp_set_service_classes(record, svclass_id);
+	sdp_list_free(svclass_id, NULL);
+
+	sdp_uuid16_create(&profile.uuid, SAP_PROFILE_ID);
+	profile.version = SAP_VERSION;
+	profiles = sdp_list_append(NULL, &profile);
+	sdp_set_profile_descs(record, profiles);
+	sdp_list_free(profiles, NULL);
+
+	sdp_uuid16_create(&l2cap, L2CAP_UUID);
+	proto[0] = sdp_list_append(NULL, &l2cap);
+	apseq = sdp_list_append(NULL, proto[0]);
+
+	sdp_uuid16_create(&rfcomm, RFCOMM_UUID);
+	proto[1] = sdp_list_append(NULL, &rfcomm);
+	ch = sdp_data_alloc(SDP_UINT8, &channel);
+	proto[1] = sdp_list_append(proto[1], ch);
+	apseq = sdp_list_append(apseq, proto[1]);
+
+	aproto = sdp_list_append(NULL, apseq);
+	sdp_set_access_protos(record, aproto);
+
+	sdp_set_info_attr(record, "SIM Access Server",
+			NULL, NULL);
+
+	sdp_data_free(ch);
+	sdp_list_free(proto[0], NULL);
+	sdp_list_free(proto[1], NULL);
+	sdp_list_free(apseq, NULL);
+	sdp_list_free(aproto, NULL);
+
+	return record;
+}
+
+static int send_message(struct sap_server *server, gchar *buf, gssize size)
+{
+	gsize written = 0;
+	GError *gerr = NULL;
+	GIOStatus gstatus;
+
+	if(!server || !buf)
+		return -1;
+
+	DBG("send_message: size=%x",(unsigned int)size);
+
+	gstatus = g_io_channel_write_chars(server->io, buf, size, &written, &gerr);
+
+	if (gstatus != G_IO_STATUS_NORMAL) {
+		if (gerr)
+			g_error_free(gerr);
+
+		error("send_message:write error (%d)", gstatus);
+		return -1;
+	}
+	if(written != (gsize)size) {
+		error("send_message:write error. written %d size %d", written, size);
+	}
+	DBG("send_message: written=%x",(unsigned int)written);
+	return 0;
+}
+
+static void connect_req(void *data, sap_parameter *param)
+{
+	struct sap_server *server = data;
+	uint16_t maxmsgsize, *val;
+
+	if(!server || !param)
+		goto error_rsp;
+
+	if (server->state != SAP_STATE_DISCONNECTED)
+		goto error_rsp;
+
+	stop_guard_timer(server);
+
+	val = (uint16_t *) &param->val;
+	maxmsgsize = ntohs(*val);
+
+	DBG("Connect MaxMsgSize: 0x%04X(%d)", maxmsgsize, maxmsgsize);
+
+	server->state = SAP_STATE_CONNECT_IN_PROGRESS;
+
+	if (maxmsgsize <= SAP_BUF_SIZE){
+		server->processing_req = SAP_CONNECT_REQ;
+		sap_connect_req(server, maxmsgsize);
+	}else{
+		sap_connect_rsp(server, SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED,
+								SAP_BUF_SIZE);
+	}
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(data);
+}
+
+static int disconnect_req(void *data, sap_disconnection_type_t disc_type)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("disconnect_req: type 0x%x state %d", disc_type, server->state);
+
+	switch(disc_type) {
+	case SAP_DISCONNECTION_TYPE_GRACEFUL:
+
+		if (server->state == SAP_STATE_DISCONNECTED ||
+				server->state == SAP_STATE_CONNECT_IN_PROGRESS)
+			goto error_req;
+
+		if (server->state == SAP_STATE_CONNECTED) {
+			server->state = SAP_STATE_GRACEFUL_DISCONNECT;
+			server->processing_req = SAP_NO_REQ;
+			disconnect_ind(server, disc_type);
+
+			/* Start guard timer - timer will disconnect connection
+			 * if client doesn't do it. */
+			start_guard_timer(server, SAP_TIMER_GRACEFUL_DISCONNECT);
+
+			return 0;
+		}
+		/* Disconnection is ongoing - do nothing. */
+		return 0;
+
+	case SAP_DISCONNECTION_TYPE_IMMEDIATE:
+
+		if (server->state == SAP_STATE_DISCONNECTED ||
+				server->state == SAP_STATE_CONNECT_IN_PROGRESS)
+			goto error_req;
+
+		if (server->state == SAP_STATE_CONNECTED ||
+				server->state == SAP_STATE_GRACEFUL_DISCONNECT) {
+			server->state = SAP_STATE_IMMEDIATE_DISCONNECT;
+			server->processing_req = SAP_NO_REQ;
+
+			stop_guard_timer(server);
+
+			disconnect_ind(server, disc_type);
+			sap_disconnect_req(server, 0);
+
+			return 0;
+		}
+		/* Disconnection is ongoing - do nothing. */
+		return 0;
+
+	case SAP_DISCONNECTION_TYPE_CLIENT:
+
+		if (server->state != SAP_STATE_CONNECTED &&
+				server->state != SAP_STATE_GRACEFUL_DISCONNECT)
+			goto error_rsp;
+
+		server->state = SAP_STATE_CLIENT_DISCONNECT;
+		server->processing_req = SAP_NO_REQ;
+
+		stop_guard_timer(server);
+
+		sap_disconnect_req(server, 0);
+
+		return 0;
+
+	default:
+		error("Unknown disconnection type (type %x).", disc_type);
+		return -EINVAL;
+	}
+
+error_rsp:
+	sap_error_rsp(server);
+error_req:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	return -EPERM;
+}
+
+static void transfer_apdu_req(void * data, sap_parameter * param)
+{
+	struct sap_server *server = data;
+
+	if(!server || !param)
+		goto error_rsp;
+
+	param->len = ntohs(param->len);
+
+	DBG("transfer_apdu_req: data %p state %d", data, server->state);
+	DBG("transfer_apdu_req: apdu param id %d  val %s len %d ",
+					param->id, param->val, param->len);
+
+	if (server->state != SAP_STATE_CONNECTED &&
+			server->state != SAP_STATE_GRACEFUL_DISCONNECT)
+		goto error_rsp;
+
+	if (server->processing_req != SAP_NO_REQ)
+		goto error_rsp;
+
+	server->processing_req = SAP_TRANSFER_APDU_REQ;
+	sap_transfer_apdu_req(server, param);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+
+static void transfer_atr_req(void * data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("transfer_atr_req: data %p state %d", data, server->state);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (server->processing_req != SAP_NO_REQ)
+		goto error_rsp;
+
+	server->processing_req = SAP_TRANSFER_ATR_REQ;
+	sap_transfer_atr_req(server);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+
+static void power_sim_off_req(void *data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("power_sim_off_req: data %p state %d", data, server->state);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (!is_power_sim_off_req_allowed(server->processing_req))
+		goto error_rsp;
+
+	server->processing_req = SAP_POWER_SIM_OFF_REQ;
+	sap_power_sim_off_req(server);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+static void power_sim_on_req(void *data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("power_sim_on_req: data %p state %d", data, server->state);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (server->processing_req != SAP_NO_REQ)
+		goto error_rsp;
+
+	server->processing_req = SAP_POWER_SIM_ON_REQ;
+	sap_power_sim_on_req(server);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+static void reset_sim_req(void *data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("reset_sim_req: data %p state %d", data, server->state);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (!is_reset_sim_req_allowed(server->processing_req))
+		goto error_rsp;
+
+	server->processing_req = SAP_RESET_SIM_REQ;
+	sap_reset_sim_req(server);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+static void transfer_card_reader_status_req(void * data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		goto error_rsp;
+
+	DBG("transfer_card_reader_status_req: data %p state %d",
+							data, server->state);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (server->processing_req != SAP_NO_REQ)
+		goto error_rsp;
+
+	server->processing_req = SAP_TRANSFER_CARD_READER_STATUS_REQ;
+	sap_transfer_card_reader_status_req(server);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+static void set_transport_protocol_req(void *data, sap_parameter *param)
+{
+	struct sap_server *server = data;
+
+	if(!server || !param)
+		goto error_rsp;
+
+	DBG("set_transport_protocol_req: data %p state %d param %p",
+						data, server->state, param);
+
+	if (server->state != SAP_STATE_CONNECTED)
+		goto error_rsp;
+
+	if (server->processing_req != SAP_NO_REQ)
+		goto error_rsp;
+
+	server->processing_req = SAP_SET_TRANSPORT_PROTOCOL_REQ;
+	sap_set_transport_protocol_req(server, param);
+
+	return;
+
+error_rsp:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	sap_error_rsp(server);
+}
+
+static int disconnect_ind(void *sap_device, sap_disconnection_type_t type)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE];
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("disconnect_ind: data %p state %d disc_type %d",
+						server, server->state, type);
+
+	if (server->state != SAP_STATE_GRACEFUL_DISCONNECT &&
+			server->state != SAP_STATE_IMMEDIATE_DISCONNECT)
+		goto error_ind;
+
+	memset(buf, 0, sizeof(buf));
+	msg->id = SAP_DISCONNECT_IND;
+	msg->nparam = 0x01;
+
+	/* Add disconnection type. */
+	param->id  = SAP_PARAM_ID_DISCONNECT_IND;
+	param->len = htons(SAP_PARAM_ID_DISCONNECT_IND_LEN);
+	*param->val = (uint8_t) type;
+	size += PARAMETER_SIZE(SAP_PARAM_ID_DISCONNECT_IND_LEN);
+
+	return send_message(sap_device, buf, size);
+
+error_ind:
+	error("Wrong state (state %x pr %x)", server->state,
+						server->processing_req);
+	return -EPERM;
+}
+
+int sap_connect_rsp(void *sap_device, sap_status_t status, uint16_t maxmsgsize)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE];
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_connect_rsp: state %x pr %x status %x", server->state,
+					server->processing_req, status);
+
+	if (server->state != SAP_STATE_CONNECT_IN_PROGRESS) {
+		return -EPERM;
+	}
+
+	memset(buf, 0, sizeof(buf));
+	msg->id = SAP_CONNECT_RESP;
+	msg->nparam = 0x01;
+
+	/* Add connection status */
+	param->id = SAP_PARAM_ID_CONN_STATUS;
+	param->len = htons(SAP_PARAM_ID_CONN_STATUS_LEN);
+	*param->val = (uint8_t)status;
+	size += PARAMETER_SIZE(SAP_PARAM_ID_CONN_STATUS_LEN);
+
+	/* Add MaxMsgSize */
+	if (maxmsgsize && (status == SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED ||
+			status == SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL)) {
+		uint16_t *len;
+		msg->nparam++;
+		/* Skip the first param */
+		param = (sap_parameter *) &buf[size];
+		param->id = SAP_PARAM_ID_MAX_MSG_SIZE;
+		param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
+		len = (uint16_t *) &param->val;
+		*len = htons(maxmsgsize);
+		size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
+	}
+
+	if (status == SAP_STATUS_OK) {
+		gboolean connected = TRUE;
+		emit_property_changed(connection, server->path, SAP_SERVER_INTERFACE,
+			"Connected", DBUS_TYPE_BOOLEAN, &connected);
+
+		server->state = SAP_STATE_CONNECTED;
+	} else {
+		server->state = SAP_STATE_DISCONNECTED;
+
+		/* Timer will shutdown channel if client doesn't send
+		 * CONNECT_REQ or doesn't shutdown channel itself.*/
+		start_guard_timer(server, SAP_TIMER_NO_ACTIVITY);
+	}
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_disconnect_rsp(void *sap_device)
+{
+	struct sap_server *server = sap_device;
+	sap_message msg = {0};
+
+	if(!server)
+		return -1;
+
+	DBG("sap_disconnect_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	switch(server->state) {
+	case SAP_STATE_CLIENT_DISCONNECT:
+		msg.id = SAP_DISCONNECT_RESP;
+
+		server->state = SAP_STATE_DISCONNECTED;
+		server->processing_req = SAP_NO_REQ;
+
+		/* Timer will close channel if client doesn't do it.*/
+		start_guard_timer(server, SAP_TIMER_NO_ACTIVITY);
+
+		return send_message(sap_device, (gchar *) &msg, sizeof(msg));
+
+	case SAP_STATE_IMMEDIATE_DISCONNECT:
+		server->state = SAP_STATE_DISCONNECTED;
+		server->processing_req = SAP_NO_REQ;
+
+		if (server->io)
+			g_io_channel_shutdown(server->io, TRUE, NULL);
+		return 0;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+int sap_transfer_apdu_rsp(void *sap_device, sap_result_t result, uint8_t *apdu,
+								uint16_t length)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_transfer_apdu_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_TRANSFER_APDU_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	if (result == SAP_RESULT_OK && (!apdu || (apdu && length == 0x00)))
+		return -EINVAL;
+
+	msg->id = SAP_TRANSFER_APDU_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, param);
+
+	/* Add APDU response. */
+	if (result == SAP_RESULT_OK) {
+		msg->nparam++;
+		/* Skipping the first param. */
+		param = (sap_parameter *) &buf[size];
+		param->id = SAP_PARAM_ID_RESPONSE_APDU;
+		param->len = htons(length);
+
+		size += PARAMETER_SIZE(length);
+		if (size > SAP_BUF_SIZE)
+			return -EOVERFLOW;
+
+		memcpy(param->val, apdu, length);
+	}
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_transfer_atr_rsp(void *sap_device, sap_result_t result, uint8_t *atr,
+								uint16_t length)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE]= {0};
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_transfer_atr_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_TRANSFER_ATR_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	if (result == SAP_RESULT_OK && (!atr || (atr && length == 0x00)))
+		return -EINVAL;
+
+	msg->id = SAP_TRANSFER_ATR_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, param);
+
+	/* Add ATR response */
+	if (result == SAP_RESULT_OK) {
+		msg->nparam++;
+		/* Skip the first param */
+		param = (sap_parameter *) &buf[size];
+		param->id = SAP_PARAM_ID_ATR;
+		param->len = htons(length);
+
+		size += PARAMETER_SIZE(length);
+		if (size > SAP_BUF_SIZE)
+			return -EOVERFLOW;
+
+		memcpy(param->val, atr, length);
+	}
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_power_sim_off_rsp(void *sap_device, sap_result_t result)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_power_sim_off_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_POWER_SIM_OFF_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	msg->id = SAP_POWER_SIM_OFF_RESP;
+
+	/* Add result code.*/
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, msg->param);
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_power_sim_on_rsp(void *sap_device, sap_result_t result)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_power_sim_on_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_POWER_SIM_ON_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	msg->id = SAP_POWER_SIM_ON_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, msg->param);
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_reset_sim_rsp(void *sap_device, sap_result_t result)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_reset_sim_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_RESET_SIM_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	msg->id = SAP_RESET_SIM_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, msg->param);
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_transfer_card_reader_status_rsp(void *sap_device, sap_result_t result,
+						icc_reader_status_t status)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_transfer_card_reader_status_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_TRANSFER_CARD_READER_STATUS_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	msg->id = SAP_TRANSFER_CARD_READER_STATUS_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, param);
+
+	/* Add card reader status. */
+	if (result == SAP_RESULT_OK) {
+		msg->nparam++;
+		/* Skipp the first param. */
+		param = (sap_parameter *) &buf[size];
+		param->id = SAP_PARAM_ID_CARD_READER_STATUS;
+		param->len = htons(SAP_PARAM_ID_CARD_READER_STATUS_LEN);
+		*param->val = (uint8_t) status;
+		size += PARAMETER_SIZE(SAP_PARAM_ID_CARD_READER_STATUS_LEN);
+	}
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_transport_protocol_rsp(void *sap_device, sap_result_t result)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_transport_protocol_rsp: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->processing_req != SAP_SET_TRANSPORT_PROTOCOL_REQ)
+		/* Ignore this response because processing (state) request
+		 * has been changed. This situation can happen e.g. when
+		 * client sends disconnect request while server is processing
+		 * another request.*/
+		return 0;
+
+	msg->id = SAP_SET_TRANSPORT_PROTOCOL_RESP;
+
+	/* Add result code */
+	msg->nparam = 0x01;
+	size += add_result_parameter(result, msg->param);
+
+	server->processing_req = SAP_NO_REQ;
+	return send_message(sap_device, buf, size);
+}
+
+int sap_error_rsp(void *sap_device)
+{
+	sap_message msg;
+
+	memset(&msg, 0, sizeof(msg));
+	msg.id = SAP_ERROR_RESP;
+
+	return send_message(sap_device, (gchar *) &msg, sizeof(msg));
+}
+
+int sap_status_ind(void *sap_device, sap_status_change_t status_change)
+{
+	struct sap_server *server = sap_device;
+	gchar buf[SAP_BUF_SIZE] = {0};
+	sap_message *msg = (sap_message *) buf;
+	sap_parameter *param = (sap_parameter *) msg->param;
+	gsize size = sizeof(sap_message);
+
+	if(!server)
+		return -1;
+
+	DBG("sap_status_ind: state %x pr %x", server->state,
+					server->processing_req);
+
+	if (server->state != SAP_STATE_CONNECTED &&
+			server->state != SAP_STATE_GRACEFUL_DISCONNECT)
+		/*Don't propagate status indication if client is not connected */
+		return 0;
+
+	msg->id = SAP_STATUS_IND;
+	msg->nparam = 0x01;
+
+	/* Add status change. */
+	param->id  = SAP_PARAM_ID_STATUS_CHANGE;
+	param->len = htons(SAP_PARAM_ID_STATUS_CHANGE_LEN);
+	*param->val = (uint8_t) status_change;
+	size += PARAMETER_SIZE(SAP_PARAM_ID_STATUS_CHANGE_LEN);
+
+	return send_message(sap_device, buf, size);
+}
+
+static int handle_cmd(void *data, gchar *buf, gsize size)
+{
+	sap_message *msg = (sap_message *) buf;
+
+	if (size < sizeof(sap_message))
+		goto error_rsp;
+
+	if (msg->nparam != 0 &&
+			size < (sizeof(sap_message) + sizeof(sap_parameter) + 4))
+		goto error_rsp;
+
+	if (check_msg(msg) < 0)
+		goto error_rsp;
+
+	switch(msg->id) {
+		case SAP_CONNECT_REQ:
+			DBG("SAP Connect.");
+			connect_req(data, msg->param);
+			return 0;
+		case SAP_DISCONNECT_REQ:
+			DBG("SAP Disconnect.");
+			disconnect_req(data, SAP_DISCONNECTION_TYPE_CLIENT);
+			return 0;
+		case SAP_TRANSFER_APDU_REQ:
+			DBG("SAP Transfer APDU.");
+			transfer_apdu_req(data, msg->param);
+			return 0;
+		case SAP_TRANSFER_ATR_REQ:
+			DBG("SAP Transfer ATR.");
+			transfer_atr_req(data);
+			return 0;
+		case SAP_POWER_SIM_OFF_REQ:
+			DBG("SAP SIM off.");
+			power_sim_off_req(data);
+			return 0;
+		case SAP_POWER_SIM_ON_REQ:
+			DBG("SAP SIM on.");
+			power_sim_on_req(data);
+			return 0;
+		case SAP_RESET_SIM_REQ:
+			DBG("SAP SIM reset.");
+			reset_sim_req(data);
+			return 0;
+		case SAP_TRANSFER_CARD_READER_STATUS_REQ:
+			DBG("SAP reader status.");
+			transfer_card_reader_status_req(data);
+			return 0;
+		case SAP_SET_TRANSPORT_PROTOCOL_REQ:
+			DBG("SAP set proto request.");
+			set_transport_protocol_req(data, msg->param);
+			return 0;
+		default:
+			DBG("SAP unknown message.");
+			break;
+	}
+
+error_rsp:
+	DBG("SAP ERROR RSP");
+	sap_error_rsp(data);
+	return -EBADMSG;
+}
+
+static gboolean sap_io_cb(GIOChannel *chan, GIOCondition cond, void *data)
+{
+	gchar buf[SAP_BUF_SIZE];
+	gsize bytes_read = 0;
+	GError *gerr = NULL;
+	GIOStatus gstatus;
+
+	if (cond & G_IO_NVAL){
+		DBG("ERR (G_IO_NVAL) on rfcomm socket.");
+		return FALSE;
+	}
+
+	if (cond & G_IO_ERR) {
+		DBG("ERR (G_IO_ERR) on rfcomm socket.");
+		return FALSE;
+	}
+
+	if (cond & G_IO_HUP ) {
+		DBG("HUP on rfcomm socket.");
+		return FALSE;
+	}
+
+	gstatus = g_io_channel_read_chars(chan, buf, sizeof(buf) - 1,
+				&bytes_read, &gerr);
+
+	if (gstatus != G_IO_STATUS_NORMAL) {
+		if(gerr)
+			g_error_free(gerr);
+		return TRUE;
+	}
+
+	if (handle_cmd(data, buf, bytes_read) < 0) {
+		error("Invalid SAP message.");
+	}
+
+	return TRUE;
+}
+
+static void sap_io_destroy(void *data)
+{
+	struct sap_server *server = data;
+
+	if (server && server->io) {
+		gboolean connected = FALSE;
+
+		stop_guard_timer(server);
+
+		g_io_channel_shutdown(server->io, TRUE, NULL);
+		g_io_channel_unref(server->io);
+
+		server->io = NULL;
+
+		if (server->state != SAP_STATE_CONNECT_IN_PROGRESS)
+			emit_property_changed(connection, server->path,
+				SAP_SERVER_INTERFACE,"Connected",
+				DBUS_TYPE_BOOLEAN, &connected);
+
+		if (server->state == SAP_STATE_CONNECT_IN_PROGRESS ||
+					server->state == SAP_STATE_CONNECTED ||
+					server->state == SAP_STATE_GRACEFUL_DISCONNECT){
+				sap_disconnect_req(NULL, 1);
+			}
+
+		server->state = SAP_STATE_DISCONNECTED;
+	}
+}
+
+static void sap_connect_cb(GIOChannel *chan, GError *gerr, gpointer data)
+{
+	struct sap_server *server = data;
+
+	if(!server)
+		return;
+
+	/* Timer will shutdown the channel in case of lack of client activity */
+	start_guard_timer(server, SAP_TIMER_NO_ACTIVITY);
+
+	g_io_add_watch_full(chan, G_PRIORITY_DEFAULT,
+			G_IO_IN | G_IO_ERR | G_IO_HUP| G_IO_NVAL,
+			(GIOFunc) sap_io_cb, server, sap_io_destroy);
+}
+
+static void connect_auth_cb(DBusError *derr, void *data)
+{
+	struct sap_server *server = data;
+	GError *gerr = NULL;
+
+	if(!server || !server->io)
+		return;
+
+	if (derr && dbus_error_is_set(derr)) {
+		error("Access denied: %s", derr->message);
+		goto drop;
+	}
+
+	if (!bt_io_accept(server->io, sap_connect_cb, server, NULL, &gerr)) {
+		error("bt_io_accept: %s", gerr->message);
+		g_error_free(gerr);
+		goto drop;
+	}
+	return;
+
+drop:
+	g_io_channel_shutdown(server->io, TRUE, NULL);
+	g_io_channel_unref(server->io);
+	server->io = NULL;
+}
+
+static void connect_confirm_cb(GIOChannel *chan, gpointer data)
+{
+	struct sap_server *server = data;
+	GError *gerr = NULL;
+	bdaddr_t src, dst;
+	int err;
+
+	if(!chan || !server)
+		return;
+
+	if (server->io)
+		goto drop;
+
+	bt_io_get(chan, BT_IO_RFCOMM, &gerr,
+			BT_IO_OPT_SOURCE_BDADDR, &src,
+			BT_IO_OPT_DEST_BDADDR, &dst,
+			BT_IO_OPT_INVALID);
+	if (gerr) {
+		error("%s", gerr->message);
+		g_error_free(gerr);
+		goto drop;
+	}
+
+	server->io = g_io_channel_ref(chan);
+
+	err = btd_request_authorization(&src, &dst, SAP_UUID, connect_auth_cb, server);
+
+	if (err < 0) {
+		DBG("Authorization denied: %s", strerror(err));
+		goto drop;
+	}
+
+	DBG("SAP incoming connection (sock %d) authorization.", g_io_channel_unix_get_fd(chan));
+
+	return;
+
+drop:
+	g_io_channel_shutdown(chan, TRUE, NULL);
+	if (server->io && server->io == chan) {
+		g_io_channel_unref(server->io);
+		server->io = NULL;
+	}
+}
+
+
+
+static inline DBusMessage *message_failed(DBusMessage *msg,
+					const char *description)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+				"%s", description);
+}
+
+static DBusMessage *enable(DBusConnection *conn,
+			DBusMessage *msg, void *data)
+{
+	struct sap_server *server = data;
+	sdp_record_t *record = NULL;
+	GIOChannel *io = NULL;
+	GError *gerr = NULL;
+
+	if (!server)
+		return message_failed(msg, "Server internal error.");
+
+	if (server->enable)
+		return message_failed(msg, "Server already enabled.");
+
+	record = create_sap_record(SAP_SERVER_CHANNEL);
+	if (!record)
+		return message_failed(msg, "Can't create SDP record for SAP.");
+
+	if (add_record_to_server(&server->src, record) < 0) {
+		sdp_record_free(record);
+		return message_failed(msg, "SDP record registration failed.");
+	}
+
+	io = bt_io_listen(BT_IO_RFCOMM, NULL, connect_confirm_cb, server, NULL, &gerr,
+			BT_IO_OPT_SOURCE_BDADDR, &server->src,
+			BT_IO_OPT_CHANNEL, SAP_SERVER_CHANNEL,
+			BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_HIGH,
+			BT_IO_OPT_MASTER, TRUE,
+			BT_IO_OPT_INVALID);
+	if (!io) {
+		g_error_free(gerr);
+		sdp_record_free(record);
+		return message_failed(msg, "Listen rfcomm channel failed.");
+	}
+
+	DBG("Listen socket %x", g_io_channel_unix_get_fd(io));
+
+	server->enable = TRUE;
+	server->record_id = record->handle;
+	server->listen_io = io;
+
+	emit_property_changed(connection, server->path, SAP_SERVER_INTERFACE,
+				"Enabled", DBUS_TYPE_BOOLEAN, &server->enable);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *disable(DBusConnection *conn,
+				DBusMessage *msg, void *data)
+{
+	struct sap_server *server = data;
+	DBusMessage *reply = NULL;
+
+	if(!server)
+		return message_failed(msg, "Server internal error.");
+
+	if (!server->enable)
+		return message_failed(msg, "Server already disabled.");
+
+	if (server->state != SAP_STATE_DISCONNECTED)
+		return message_failed(msg, "Ongoing connection exists.");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	remove_record_from_server(server->record_id);
+
+	if (server->listen_io) {
+		g_io_channel_shutdown(server->listen_io, TRUE, NULL);
+		g_io_channel_unref(server->listen_io);
+		server->listen_io = NULL;
+	}
+
+	server->enable = FALSE;
+
+	emit_property_changed(connection, server->path, SAP_SERVER_INTERFACE,
+				"Enabled", DBUS_TYPE_BOOLEAN, &server->enable);
+
+	return reply;
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+				DBusMessage *msg, void *data)
+{
+	struct sap_server *server = data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	dbus_bool_t connected;
+
+	if(!server)
+		return message_failed(msg, "Server internal error.");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	dict_append_entry(&dict, "Enabled", DBUS_TYPE_BOOLEAN, &server->enable);
+
+	connected = (server->state == SAP_STATE_CONNECTED ||
+			server->state == SAP_STATE_GRACEFUL_DISCONNECT);
+	dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &connected);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
+static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct sap_server *server = data;
+	dbus_bool_t disc_type;
+	sap_disconnection_type_t sap_disc_type;
+
+	if (!server)
+		return message_failed(msg, "Server internal error.");
+
+	if (!server->enable)
+		return g_dbus_create_error(msg, ERROR_INTERFACE
+				".Failed",
+				"Server already disabled");
+
+	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &disc_type,
+						DBUS_TYPE_INVALID) == FALSE)
+		return NULL;
+
+	sap_disc_type = disc_type ? SAP_DISCONNECTION_TYPE_GRACEFUL :
+				SAP_DISCONNECTION_TYPE_IMMEDIATE;
+	if (disconnect_req(server, sap_disc_type) < 0)
+		return g_dbus_create_error(msg, ERROR_INTERFACE
+				".Failed",
+				"There is no active connection");
+
+	return dbus_message_new_method_return(msg);
+}
+
+static GDBusMethodTable server_methods[] = {
+	{ "Enable","","", enable },
+	{ "Disable","","", disable },
+	{ "GetProperties","","a{sv}",get_properties },
+	{ "Disconnect","b","", disconnect },
+	{ }
+};
+
+static GDBusSignalTable server_signals[] = {
+	{ "PropertyChanged",		"sv"},
+	{ }
+};
+
+static void server_free(struct sap_server *server)
+{
+	DBG("[%s::%s]", __FILE__, __FUNCTION__);
+
+	if (!server)
+		return;
+
+	g_free(server->path);
+	g_free(server);
+}
+
+static void destroy_sap_interface(void *data)
+{
+	struct sap_server *server = data;
+
+	DBG("Unregistered interface %s on path %s",
+			SAP_SERVER_INTERFACE, server->path);
+
+	server_free(server);
+}
+
+int sap_server_register(const char *path, bdaddr_t *src)
+{
+	struct sap_server *server;
+
+	if(sap_init() < 0) {
+		error("Sap driver initialization failed.");
+		return -1;
+	}
+
+	server = g_new0(struct sap_server, 1);
+
+	if (!server) {
+		sap_exit();
+		return -ENOMEM;
+	}
+
+	server->enable = FALSE;
+
+	if (!g_dbus_register_interface(connection, path, SAP_SERVER_INTERFACE,
+				server_methods, server_signals, NULL,
+				server, destroy_sap_interface)) {
+		error("D-Bus failed to register %s interface",
+						SAP_SERVER_INTERFACE);
+		server_free(server);
+		sap_exit();
+		return -1;
+	}
+
+	server->path = g_strdup(path);
+	bacpy(&server->src, src);
+
+	return 0;
+}
+
+int sap_server_unregister(const char *path)
+{
+	g_dbus_unregister_interface(connection, path, SAP_SERVER_INTERFACE);
+	sap_exit();
+	return 0;
+}
+
+int sap_server_init(DBusConnection *conn)
+{
+	connection = dbus_connection_ref(conn);
+	return 0;
+}
+
+void sap_server_exit(void)
+{
+	dbus_connection_unref(connection);
+	connection = NULL;
+}
diff --git a/sap/server.h b/sap/server.h
new file mode 100644
index 0000000..6e7f6fc
--- /dev/null
+++ b/sap/server.h
@@ -0,0 +1,23 @@
+/*
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2010 Claudio Takahasi<claudio.takahasi@openbossa.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+int sap_server_init(DBusConnection *conn);
+void sap_server_exit(void);
+int sap_server_register(const char *path, bdaddr_t *src);
+int sap_server_unregister(const char *path);
-- 
1.7.0.4

^ permalink raw reply related

* [Lustre-devel] Queries regarding LDLM_ENQUEUE
From: Andreas Dilger @ 2010-10-20  7:55 UTC (permalink / raw)
  To: lustre-devel
In-Reply-To: <AANLkTik53-vQLA9DTj858=San9fgMB+94i8eChvHomEK@mail.gmail.com>

On 2010-10-19, at 20:04, Vilobh Meshram wrote:
> We are trying to do following things.Please let me know if things are not clear :-
> 
> Say we have 2 client C1 and C2 and a MDS .Say C1 and C2 share a file.
> 1) When a client C1 performs a open/create kind of request to the MDS we want to follow the normal path which Lustre performs.
> 2) Now say C2 tries to open the same file which was opened by C1.
> 3) At the MDS end we maintain some data structure to scan and see if the file was already opened by some Client(in this case C1 has opened this file).
> 4) If MDS finds that some client(C1 here) has already opened the file then it send the new client(C2 here) with some information about the client which has initially opened the file.

While I understand the basic concept, I don't really see how your proposal will actually improve performance.  If C2 already has to contact the MDS and get a reply from it, then wouldn't it be about the same to simply perform the open as is done today?  The number of MDS RPCs is the same, and in fact this would avoid further message overhead between C1 and C2.

> 5) Once C2 gets the information its upto C2 to take further actions.
> 6) By this process we can save the time spent in the locking mechanism for C2.Basically we aim to by-pass the locking scheme of Lustre for the files already opened by some client by maintaining some kind of data structure.
> 
> Please let us know your thoughts on the above approach.Is this a feasible design moving ahead can we see any complications ?

There is a separate proposal that has been underway in the Linux community for some time, to allow a user process to get a file handle (i.e. binary blob returned from a new name_to_handle() syscall) from the kernel for a given pathname, and then later use that file handle in another process to open a file descriptor without re-traversing the path.

I've been thinking this would be very useful for Lustre (and MPI in general), and have tried to steer the Linux development in a direction that would allow this to happen.  Is this in line with what you are investigating?

While this wouldn't eliminate the actual MDS open RPC (i.e. the LDLM_ENQUEUE you have been discussing), it could avoid the path traversal from each client, possibly saving {path_elements * num_clients} additional RPCs,

> So considering the problem statement I need a way for C2 to extract the information from the data structure maintained at MDS.In order to do that , C2 will send a request with intent = create|open which will be a LDLM_ENQUEUE RPC.I need to modify this RPC such that :-
> 1) I can enclose some additional buffer whose size is known to me .
> 2) When we pack the reply at the MDS side we should be able to include this buffer in the reply message .
> 3) At the client side we should be able to extract the information from the reply message about the buffer.
> 
> As of now , I need help in above three steps.
> 
> Thanks,
> Vilobh
> Graduate Research Associate
> Department of Computer Science
> The Ohio State University Columbus Ohio
> 
> 
> On Tue, Oct 19, 2010 at 6:53 PM, Andreas Dilger <andreas.dilger@oracle.com> wrote:
> On 2010-10-19, at 14:28, Vilobh Meshram wrote:
> > From my exploration it seems like for create/open kind of request LDLM_ENQUEUE is the RPC through which the client talks to MDS.Please confirm on this.
> >
> > Since I could figure out that LDLM_ENQUEUE is the only RPC to interface with MDS I am planning to send the LDLM_ENQUEUE RPC with some additonal buffer from the client to the MDS so that based on some specific condition the MDS can fill the information in the buffer sent from the client.
> 
> This isn't correct.  LDLM_ENQUEUE is used for enqueueing locks.  It just happens that when Lustre wants to create a new file it enqueues a lock on the parent directory with the "intent" to create a new file.  The MDS currently always replies "you cannot have the lock for the directory, I created the requested file for you".  Similarly, when the client is getting attributes on a file, it needs a lock on that file in order to cache the attributes, and to save RPCs the attributes are returned with the lock.
> 
> > I have made some modifications to the code for the LDLM_ENQUEUE RPC but I am getting kernel panics.Can someone please help me and suggest me what is a good way to tackle this problem.I am using Lustre 1.8.1.1 and I cannot upgrade to Lustre 2.0.
> 
> It would REALLY be a lot easier to have this discussion with you if you actually told us what it is you are working on.  Not only could we focus on the higher-level issue that you are trying to solve (instead of possibly wasting a lot of time focussing in a small issue that may in fact be completely irrelevant), but with many ideas related to Lustre it has probably already been discussed at length by the Lustre developers sometime over the past 8 years that we've been working on it.  I suspect that the readership of this list could probably give you a lot of assistance with whatever you are working on, if you will only tell us what it actually is you are trying to do.
> 
> > On Mon, Oct 18, 2010 at 7:33 PM, Vilobh Meshram <vilobh.meshram@gmail.com> wrote:
> >> Out of the many RPC's used in Lustre seems like LDLM_ENQUEUE is the most frequently used RPC to communicate between the client and the MDS.I have few queries regarding the same :-
> >>
> >> 1) Is LDLM_ENQUEUE the only interface(RPC here) for CREATE/OPEN kind of request ; through which the client can interact with the MDS ?
> >>
> >> I tried couple of experiments and found out that LDLM_ENQUEUE comes into picture while mounting the FS as well as when we do a lookup,create or open a file.I was expecting the MDS_REINT RPC to get invoked in case of a CREATE/OPEN request via mdc_create() but it seems like Lustre invokes LDLM_ENQEUE even for CREATE/OPEN( by packing the intent related data).
> >> Please correct me if I am wrong.
> >>
> >> 2) In which cases (which system calls) does the MDS_REINT RPC will get invoked ?
> 
> 
> Cheers, Andreas
> --
> Andreas Dilger
> Lustre Technical Lead
> Oracle Corporation Canada Inc.
> 
> 


Cheers, Andreas
--
Andreas Dilger
Lustre Technical Lead
Oracle Corporation Canada Inc.

^ permalink raw reply

* RE: Change signal mask after vfork/clone system call
From: Gregory Giguashvili @ 2010-10-20  7:56 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org
In-Reply-To: <DAF636D3923A51488784A1F985996EE803FCB7B0@exil1.paradigmgeo.net>

Any comments on this issue? If you think this mailing list is not appropriate for submitting such questions, I would appreciate a pointer to the one that is.
To me, it seems to be related to "clone" system call functionality and flexibility.

Thanks
Giga

-----Original Message-----
From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of Gregory Giguashvili
Sent: Tuesday, October 19, 2010 9:54 AM
To: linux-kernel@vger.kernel.org
Subject: Change signal mask after vfork/clone system call

For new processes created by vfork, while signals are blocked using pthread_sigmask: is there a way in a multi-threaded parent to safely unblock signals before the new process is started? Does pthread_atfork like functionality exist for vfork-ed processes maybe?

Ideally, the following code should work, except we're not allowed to call anything in the child process besides exec family of functions.

sigmask_t new;
sigmask_t old;
sigaddset (&new, SIGCHLD);
pthread_sigmask (SIG_BLOCK, &new, &old);

switch (vfork ()) {
case 0: // parent
	break;
case -1: // error
	break;
default: // child
	pthread_sigmask (SIG_SETMASK, &old, NULL);
	execv (...);
	_exit (-1);
}

Finally, if using fork should be efficient for starting processes from applications with heavy VM/RSS memory footprint, this question becomes obsolete.

Thanks
Giga

---------------------------------------------------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.



^ permalink raw reply

* [PATCH 3/4] ARM: S5PV210: I2S: Upgrade platform device
From: Kukjin Kim @ 2010-10-20  7:57 UTC (permalink / raw)
  To: linux-arm-kernel
In-Reply-To: <1287472511-529-1-git-send-email-jassisinghbrar@gmail.com>

Jassi Brar wrote:
> 
> From: Jassi Brar <jassi.brar@samsung.com>
> 
> Add more information to I2S platform_devices in order
> to prepare them for new controller driver.
> 
> Signed-off-by: Jassi Brar <jassi.brar@samsung.com>
> ---
>  arch/arm/mach-s5pv210/clock.c     |   10 +++---
>  arch/arm/mach-s5pv210/dev-audio.c |   64
++++++++++++++++++++++++++---------
> -
>  2 files changed, 51 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/arm/mach-s5pv210/clock.c b/arch/arm/mach-s5pv210/clock.c
> index af91fef..e5b8061 100644
> --- a/arch/arm/mach-s5pv210/clock.c
> +++ b/arch/arm/mach-s5pv210/clock.c
> @@ -401,20 +401,20 @@ static struct clk init_clocks_disable[] = {
>  		.enable		= s5pv210_clk_ip3_ctrl,
>  		.ctrlbit	= (1<<21),
>  	}, {
> -		.name		= "i2s_v50",
> +		.name		= "iis",
>  		.id		= 0,
>  		.parent		= &clk_p,
>  		.enable		= s5pv210_clk_ip3_ctrl,
>  		.ctrlbit	= (1<<4),
>  	}, {
> -		.name		= "i2s_v32",
> -		.id		= 0,
> +		.name		= "iis",
> +		.id		= 1,
>  		.parent		= &clk_p,
>  		.enable		= s5pv210_clk_ip3_ctrl,
>  		.ctrlbit	= (1 << 5),
>  	}, {
> -		.name		= "i2s_v32",
> -		.id		= 1,
> +		.name		= "iis",
> +		.id		= 2,
>  		.parent		= &clk_p,
>  		.enable		= s5pv210_clk_ip3_ctrl,
>  		.ctrlbit	= (1 << 6),
> diff --git a/arch/arm/mach-s5pv210/dev-audio.c
b/arch/arm/mach-s5pv210/dev-
> audio.c
> index 6e60041..d5f5361 100644
> --- a/arch/arm/mach-s5pv210/dev-audio.c
> +++ b/arch/arm/mach-s5pv210/dev-audio.c
> @@ -19,10 +19,24 @@
>  #include <mach/dma.h>
>  #include <mach/irqs.h>
> 
> +static const char *rclksrc[] = {
> +	[0] = "busclk",
> +	[1] = "i2sclk",
> +};
> +
>  static int s5pv210_cfg_i2s(struct platform_device *pdev)
>  {
>  	/* configure GPIO for i2s port */
>  	switch (pdev->id) {
> +	case 0:
> +		s3c_gpio_cfgpin(S5PV210_GPI(0), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(1), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(2), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(3), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(4), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(5), S3C_GPIO_SFN(2));
> +		s3c_gpio_cfgpin(S5PV210_GPI(6), S3C_GPIO_SFN(2));

s3c_gpio_cfgpin_range(S5PV210_GPI(0), 7, S3C_GPIO_SFN(2))?

Hmm...
It would be helpful to me if you could make your patch which is regarding
arch/arm/ against on my for-next.

> +		break;
>  	case 1:
>  		s3c_gpio_cfgpin(S5PV210_GPC0(0), S3C_GPIO_SFN(2));
>  		s3c_gpio_cfgpin(S5PV210_GPC0(1), S3C_GPIO_SFN(2));
> @@ -30,7 +44,6 @@ static int s5pv210_cfg_i2s(struct platform_device *pdev)
>  		s3c_gpio_cfgpin(S5PV210_GPC0(3), S3C_GPIO_SFN(2));
>  		s3c_gpio_cfgpin(S5PV210_GPC0(4), S3C_GPIO_SFN(2));
>  		break;
> -
>  	case 2:
>  		s3c_gpio_cfgpin(S5PV210_GPC1(0), S3C_GPIO_SFN(4));
>  		s3c_gpio_cfgpin(S5PV210_GPC1(1), S3C_GPIO_SFN(4));
> @@ -38,17 +51,6 @@ static int s5pv210_cfg_i2s(struct platform_device
*pdev)
>  		s3c_gpio_cfgpin(S5PV210_GPC1(3), S3C_GPIO_SFN(4));
>  		s3c_gpio_cfgpin(S5PV210_GPC1(4), S3C_GPIO_SFN(4));
>  		break;
> -
> -	case -1:
> -		s3c_gpio_cfgpin(S5PV210_GPI(0), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(1), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(2), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(3), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(4), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(5), S3C_GPIO_SFN(2));
> -		s3c_gpio_cfgpin(S5PV210_GPI(6), S3C_GPIO_SFN(2));
> -		break;
> -
>  	default:
>  		printk(KERN_ERR "Invalid Device %d\n", pdev->id);
>  		return -EINVAL;
> @@ -57,8 +59,15 @@ static int s5pv210_cfg_i2s(struct platform_device
*pdev)
>  	return 0;
>  }
> 
> -static struct s3c_audio_pdata s3c_i2s_pdata = {
> +static struct s3c_audio_pdata i2sv5_pdata = {
>  	.cfg_gpio = s5pv210_cfg_i2s,
> +	.type = {
> +		.i2s = {
> +			.quriks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
> +					 | QUIRK_NEED_RSTCLR,
> +			.src_clk = rclksrc,
> +		},
> +	},
>  };
> 
>  static struct resource s5pv210_iis0_resource[] = {
> @@ -77,15 +86,34 @@ static struct resource s5pv210_iis0_resource[] = {
>  		.end   = DMACH_I2S0_RX,
>  		.flags = IORESOURCE_DMA,
>  	},
> +	[3] = {
> +		.start = DMACH_I2S0S_TX,
> +		.end   = DMACH_I2S0S_TX,
> +		.flags = IORESOURCE_DMA,
> +	},
>  };
> 
>  struct platform_device s5pv210_device_iis0 = {
> -	.name		  = "samsung-i2s-v4",
> -	.id		  = -1,
> +	.name		  = "samsung-i2s",
> +	.id		  = 0,
>  	.num_resources	  = ARRAY_SIZE(s5pv210_iis0_resource),
>  	.resource	  = s5pv210_iis0_resource,
>  	.dev = {
> -		.platform_data = &s3c_i2s_pdata,
> +		.platform_data = &i2sv5_pdata,
> +	},
> +};
> +
> +static const char *rclksrc_v3[] = {
> +	[0] = "iis",
> +	[1] = "audio-bus",
> +};
> +
> +static struct s3c_audio_pdata i2sv3_pdata = {
> +	.cfg_gpio = s5pv210_cfg_i2s,
> +	.type = {
> +		.i2s = {
> +			.src_clk = rclksrc_v3,
> +		},
>  	},
>  };
> 
> @@ -113,7 +141,7 @@ struct platform_device s5pv210_device_iis1 = {
>  	.num_resources	  = ARRAY_SIZE(s5pv210_iis1_resource),
>  	.resource	  = s5pv210_iis1_resource,
>  	.dev = {
> -		.platform_data = &s3c_i2s_pdata,
> +		.platform_data = &i2sv3_pdata,
>  	},
>  };
> 
> @@ -141,7 +169,7 @@ struct platform_device s5pv210_device_iis2 = {
>  	.num_resources	  = ARRAY_SIZE(s5pv210_iis2_resource),
>  	.resource	  = s5pv210_iis2_resource,
>  	.dev = {
> -		.platform_data = &s3c_i2s_pdata,
> +		.platform_data = &i2sv3_pdata,
>  	},
>  };
> 
> --
> 1.6.2.5


Thanks.

Best regards,
Kgene.
--
Kukjin Kim <kgene.kim@samsung.com>, Senior Engineer,
SW Solution Development Team, Samsung Electronics Co., Ltd.

^ permalink raw reply

* Re: [lm-sensors] [PATCH 1/2] hwmon: add generic GPIO fan driver
From: Simon Guinot @ 2010-10-20  7:59 UTC (permalink / raw)
  To: linux-arm-kernel
In-Reply-To: <1287535826.9690.358.camel@groeck-laptop>


[-- Attachment #1.1: Type: text/plain, Size: 2068 bytes --]

Hi Guenter,

On Tue, Oct 19, 2010 at 05:50:26PM -0700, Guenter Roeck wrote:
> Hi Simon,
> 
> On Tue, 2010-10-19 at 20:19 -0400, Simon Guinot wrote:
> > Hi Guenter,
> > 
> > On Tue, Oct 19, 2010 at 03:03:45PM -0700, Guenter Roeck wrote:
> > > Hi Simon,
> > > 
> > > one more comment ...
> > > 
> > > On Sun, 2010-10-17 at 11:50 -0400, Simon Guinot wrote:
> > > [ ... ]
> > > > +static int __devinit
> > > > +fan_alarm_init(struct gpio_fan_data *fan_data, struct gpio_fan_alarm *alarm)
> > > > +{
> > > 
> > > __devinit and __devexit can cause problems if this driver is built into
> > > the kernel, but the underlying i2c master driver is built as module.
> > 
> > I am not sure I understand this. Are you talking about a I2C GPIO
> > expander ? or about the hwmon registration process ?
> 
> Not related to I2C specifically, since you don't use I2C. No idea why I
> mentioned I2C, really. Probably because I had I2C in my mind.

gpio-fan could use I2C implicitly if the GPIOs are provided by a GPIO
I2C expander.

> 
> Anyway, there are gpio drivers which can be loaded and unloaded. GPIO
> pin(s) on one of those could point to the gpio-fan driver. If gpio-fan
> is built into the kernel, but the underlying gpio driver is built as
> module, loading the gpio driver might cause the gpio-fan probe function
> to be called - but that function no longer exists if it is tagged as
> __devinit.

IMHO, the gpio-fan probe function will be called anyway if a "gpio-fan"
platform device is available. If the needed GPIOs are not registered at
this time, gpio_request() will fail and the gpio-fan probe function will
exit.

Later, even if the GPIOs are registered (via gpiochip_add()), this will
not trigger a gpio-fan probe.

> 
> Browsing through the gpio code, it seems the problem doesn't really
> exist, since the above scenario does not happen (unless I am missing
> something, of course). Also, other drivers using gpio calls also use
> __devinit and __devexit. So just ignore what I said.

Ok.

Thanks,

Simon

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply

* [PATCH 1/2] hwmon: add generic GPIO fan driver
From: Simon Guinot @ 2010-10-20  7:59 UTC (permalink / raw)
  To: linux-arm-kernel
In-Reply-To: <1287535826.9690.358.camel@groeck-laptop>

Hi Guenter,

On Tue, Oct 19, 2010 at 05:50:26PM -0700, Guenter Roeck wrote:
> Hi Simon,
> 
> On Tue, 2010-10-19 at 20:19 -0400, Simon Guinot wrote:
> > Hi Guenter,
> > 
> > On Tue, Oct 19, 2010 at 03:03:45PM -0700, Guenter Roeck wrote:
> > > Hi Simon,
> > > 
> > > one more comment ...
> > > 
> > > On Sun, 2010-10-17 at 11:50 -0400, Simon Guinot wrote:
> > > [ ... ]
> > > > +static int __devinit
> > > > +fan_alarm_init(struct gpio_fan_data *fan_data, struct gpio_fan_alarm *alarm)
> > > > +{
> > > 
> > > __devinit and __devexit can cause problems if this driver is built into
> > > the kernel, but the underlying i2c master driver is built as module.
> > 
> > I am not sure I understand this. Are you talking about a I2C GPIO
> > expander ? or about the hwmon registration process ?
> 
> Not related to I2C specifically, since you don't use I2C. No idea why I
> mentioned I2C, really. Probably because I had I2C in my mind.

gpio-fan could use I2C implicitly if the GPIOs are provided by a GPIO
I2C expander.

> 
> Anyway, there are gpio drivers which can be loaded and unloaded. GPIO
> pin(s) on one of those could point to the gpio-fan driver. If gpio-fan
> is built into the kernel, but the underlying gpio driver is built as
> module, loading the gpio driver might cause the gpio-fan probe function
> to be called - but that function no longer exists if it is tagged as
> __devinit.

IMHO, the gpio-fan probe function will be called anyway if a "gpio-fan"
platform device is available. If the needed GPIOs are not registered at
this time, gpio_request() will fail and the gpio-fan probe function will
exit.

Later, even if the GPIOs are registered (via gpiochip_add()), this will
not trigger a gpio-fan probe.

> 
> Browsing through the gpio code, it seems the problem doesn't really
> exist, since the above scenario does not happen (unless I am missing
> something, of course). Also, other drivers using gpio calls also use
> __devinit and __devexit. So just ignore what I said.

Ok.

Thanks,

Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101020/62a4f0e4/attachment.sig>

^ permalink raw reply

* [U-Boot] ARM: Warning with current master
From: Matthias Weißer @ 2010-10-20  7:59 UTC (permalink / raw)
  To: u-boot
In-Reply-To: <4CBE9DC7.8020105@free.fr>

Am 20.10.2010 09:44, schrieb Albert ARIBAUD:
> Le 20/10/2010 09:22, Matthias Wei?er a ?crit :
>> Hi
>>
>> after pulling the latest changes I get the following warning during
>> linking of arm boards (I tested jadecpu and tx25).
>>
>> arm-unknown-eabi-ld: warning: creating a DT_TEXTREL in object.
>
> Hmm... Which toolchain do you use?

I build it myself using crosstools-ng

$ arm-unknown-eabi-gcc -v
Using built-in specs.
Target: arm-unknown-eabi
Configured with: ~/ctdev/targets/src/gcc-4.3.4/configure 
--build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu 
--target=arm-unknown-eabi --prefix=~/x-tools/arm-unknown-eabi 
--with-local-prefix=~/x-tools/arm-unknown-eabi/arm-unknown-eabi//sys-root --disable-multilib 
--disable-libmudflap 
--with-sysroot=~/x-tools/arm-unknown-eabi/arm-unknown-eabi//sys-root 
--with-newlib --enable-threads=no --disable-shared 
--with-pkgversion=crosstool-NG-1.8.0 --disable-__cxa_atexit 
--with-gmp=~/ctdev/targets/arm-unknown-eabi/build/static 
--with-mpfr=~/ctdev/targets/arm-unknown-eabi/build/static 
--enable-target-optspace --disable-nls --enable-symvers=gnu 
--enable-languages=c,c++
Thread model: single
gcc version 4.3.4 (crosstool-NG-1.8.0)

Hope this helps.

Matthias

^ permalink raw reply

* Re: fetch and bundle don't work in (semi-)broken repo
From: Uwe Kleine-König @ 2010-10-20  7:59 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Jonathan Nieder, git
In-Reply-To: <alpine.LFD.2.00.1010191635030.2764@xanadu.home>

Hello,

On Tue, Oct 19, 2010 at 04:48:23PM -0400, Nicolas Pitre wrote:
> On Tue, 19 Oct 2010, Uwe Kleine-König wrote:
> 
> > Hi Jonathan,
> > 
> > On Tue, Oct 19, 2010 at 01:39:25PM -0500, Jonathan Nieder wrote:
> > > Uwe Kleine-König wrote:
> > > 
> > > > 	ukl@hostname:~/path1/linux-2.6$ git fetch ~/path2/linux-2.6 sectionmismatches
> > > > 	remote: Counting objects: 118, done.
> > > > 	remote: error: unable to find 40aaeb204dc04d3cf15c060133f65538b43b13b0
> > > > 	remote: Compressing objects: 100% (83/83), done.
> > > > 	remote: fatal: unable to read 40aaeb204dc04d3cf15c060133f65538b43b13b0
> > > > 	error: git upload-pack: git-pack-objects died with error.
> > > > 	fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
> > > 
> > > Sounds like alternates or workdir allowed gc to be overzealous, indeed.
> > > 
> > > Could you:
> > > 
> > >  1. Make a copy of the corrupted repo, just in case.
> > >  2. Explode all backs with "git unpack-objects"
> 
> That's usually unnecessary.  If the pack itself is corrupted, trying to 
> unpack it all won't help.
> 
> > I did:
> > 
> > 	mv .git/objects/pack .git/objects/pack.bak
> > 	rm .git/objects/info/alternates
> > 	for p in .git/objects/pack.bak/*.pack ~/path1/linux-2.6/.git/objects/pack/*.pack; do
> > 		git unpack-objects < $p
> > 	done
> 
> Ouch!  You will end up with a multi-gigabyte repository, which will be 
> abominably slow.
> 
> > >  3. Identify the missing object, as explained in
> > >     Documentation/howto/recover-corrupted-blob-object.txt?
> 
> That's useful when you have only one corrupted object and you want to 
> recreate it from raw material.  But ideally you should simply find a 
> pack that contains the problematic object in another repository and copy 
> it with its index 
> file into the broken repository.
> 
> > and I'm running git-fsck --full now over night as it's bedtime here.
> 
> Given that you exploded your repo into loose objects, it'll take _time_.
Well it took 34 minutes, which is OK I guess.

I will study the output a bit now.

For the interested (all lines matching "dangling" removed):

	22:10:57 I: Started git fsck --full
	22:44:14 O: broken link from    tree 519af383e181399db929823299bbd14c04b4229a
	22:44:14 O: to    tree d58c333c44672cb933df5a353dfb63ac571964e8
	22:44:14 O: broken link from  commit e8f7f6a23979c398249a15fb71b3e52dae933fa3
	22:44:14 O: to    tree 7f22979d86cf00c8bd3487feb973353ab5a1beee
	22:44:14 O: broken link from  commit 3164f6598ae44703a89822ced9746c1876ba7fab
	22:44:14 O: to    tree 1017bb1f45b8527ee3c7cfc30288b8098bcf0915
	22:44:14 O: broken link from  commit 124dde2ea387dc9509b0a5574c6f44f7d348a65d
	22:44:14 O: to    tree e4d0ac236995847e4e1d15c6d0afb47787255703
	22:44:14 O: broken link from  commit 60deff2fffd90b217d90284295d5a910f21fe98e
	22:44:14 O: to    tree 18bb32cfd08228820f929d62e63933fe2896b424
	22:44:14 O: broken link from  commit 0b84e651b84dba73772fda15a8a66de8cc274af0
	22:44:14 O: to    tree f8939a09d73b78459381b7991423529592e66324
	22:44:14 O: broken link from  commit e0de1d3c3355f9b1e3474417f05657a1041e7c8a
	22:44:14 O: to    tree 776ad9ac45dab11f2644151a690e1035789a49b6
	22:44:14 O: broken link from  commit 76d1acb95eef413a2501a63cb7f7f4036b71ed37
	22:44:14 O: to  commit f6b6cb2336198913371e66664f28c135df01aea5
	22:44:14 O: broken link from    tree bb473ad85c260b6a1659aa2059cac23b337842e3
	22:44:14 O: to    tree e035bc14698cc3e9abfca1a174feacb25e7e262a
	22:44:14 O: broken link from    tree bb473ad85c260b6a1659aa2059cac23b337842e3
	22:44:14 O: to    tree 8908b2458c1a2c6a6db81e88d96a01aa9a89abe5
	22:44:14 O: broken link from    tree ee35b3a549f45830ed50eb1032836a71ab2b7886
	22:44:14 O: to    tree f2f33722af4b5e32ac17f914cf24cc96c6e80077
	22:44:14 O: broken link from    tree ee35b3a549f45830ed50eb1032836a71ab2b7886
	22:44:14 O: to    tree 70f0188991b8406ec6ec75a504cf50c778fc1001
	22:44:14 O: broken link from    tree 1772732da7d4751d3c0febd7b0ceee61a84702f0
	22:44:14 O: to    tree dc3c1a018fcf2797a860af0cb899fe6be1173da3
	22:44:14 O: broken link from    tree 1772732da7d4751d3c0febd7b0ceee61a84702f0
	22:44:14 O: to    tree 2ade2c0731e57fc6b1baddb6faf683847d706179
	22:44:14 O: broken link from    tree 1772732da7d4751d3c0febd7b0ceee61a84702f0
	22:44:14 O: to    tree 659f4a6280150b7ae7b8f824257ad3cbb7cd1788
	22:44:14 O: broken link from    tree f29915a03ea5ba8739aacfcbb349d40b019481ed
	22:44:14 O: to    tree b52d608d7743b1e096725d4b8d7c7769b19f6674
	22:44:15 O: missing tree 7f22979d86cf00c8bd3487feb973353ab5a1beee
	22:44:15 O: missing tree 70f0188991b8406ec6ec75a504cf50c778fc1001
	22:44:15 O: missing tree dc3c1a018fcf2797a860af0cb899fe6be1173da3
	22:44:15 O: missing tree f8939a09d73b78459381b7991423529592e66324
	22:44:15 O: missing tree e4d0ac236995847e4e1d15c6d0afb47787255703
	22:44:15 O: missing tree 2ade2c0731e57fc6b1baddb6faf683847d706179
	22:44:15 O: missing tree 8908b2458c1a2c6a6db81e88d96a01aa9a89abe5
	22:44:15 O: missing tree 18bb32cfd08228820f929d62e63933fe2896b424
	22:44:15 O: missing tree d58c333c44672cb933df5a353dfb63ac571964e8
	22:44:15 O: missing tree f2f33722af4b5e32ac17f914cf24cc96c6e80077
	22:44:16 O: missing tree 1017bb1f45b8527ee3c7cfc30288b8098bcf0915
	22:44:16 O: missing tree e035bc14698cc3e9abfca1a174feacb25e7e262a
	22:44:16 O: missing tree 659f4a6280150b7ae7b8f824257ad3cbb7cd1788
	22:44:16 O: missing commit f6b6cb2336198913371e66664f28c135df01aea5
	22:44:16 O: missing tree 776ad9ac45dab11f2644151a690e1035789a49b6
	22:44:16 O: missing tree b52d608d7743b1e096725d4b8d7c7769b19f6674
	22:44:16 O: missing blob 40aaeb204dc04d3cf15c060133f65538b43b13b0

Here is the output for the object bundle and fetch wail about, but
nothing about a tree that would need it :-(  Actually it's the only one
of the missing objects that is not described above (and it's the only
blob).

	22:44:17 I: Finished with exitcode 2

Now I'm running

	git for-each-ref | while read sha type name; do
		echo $name;
		git log --raw --full-history $sha | grep 40aaeb204dc04d3cf15c060133f65538b43b13b0;
	done

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply

* [PATCH] Documentation about RS485 serial communications
From: Alexander Stein @ 2010-10-20  8:00 UTC (permalink / raw)
  To: linux-arm-kernel
In-Reply-To: <i9kk4o$svc$1@dough.gmane.org>

On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Out of curiosity, how can I add RS485 (or whatever) support for other serial 
devices like e.g. i.mx serial? Is there some driver independent interface 
which only gets filled in board configs like setting some GPIO pins?

Alexander

^ permalink raw reply

* Re: [xen-4.0-testing test] 2371: tolerable FAIL - PUSHED, saverestore failures
From: Ian Campbell @ 2010-10-20  8:00 UTC (permalink / raw)
  To: Ian Jackson; +Cc: xen-devel@lists.xensource.com
In-Reply-To: <19645.31053.217191.813235@mariner.uk.xensource.com>

On Tue, 2010-10-19 at 11:56 +0100, Ian Jackson wrote:
> Ian Campbell writes ("Re: [Xen-devel] [xen-4.0-testing test] 2371: tolerable FAIL - PUSHED, saverestore failures"):
> > Actually, that patch is more to do with the guest-saverestore.2
> > failures. I'll likely get onto the migration failures next, assuming
> > it's not the same issue.
> 
> I think we discussed the migration failures before.  My memory is
> vague but I remember a conversation about missing gratuitous arps.

Oh yes, I remember now. I think we determined this was not an issue in
your test infrastructure due to some daemon which does regular ARP
requests.

> However looking at the logs the guest kernel oopses, immediately on
> arrival at the destination.
> 
> I think this is necessarily the same problem as the
> second-save-restore crash, since this is the first attempt to migrate
> or save/restore this guest.

Yes judging from the stack trace it's certainly very much related, if
not precisely the same.

Ian.

> 
> Ian.
> 
> [   42.254308] BUG: unable to handle kernel paging request at b72050a0
> [   42.254308] IP: [<c102bc76>] xen_build_mfn_list_list+0x12f/0x14b
> [   42.254308] *pdpt = 000000001fcbd007 *pde = 0000000000000000 
> [   42.254308] Oops: 0002 [#1] SMP 
> [   42.254308] last sysfs file: /sys/kernel/uevent_seqnum
> [   42.254308] Modules linked in: [last unloaded: scsi_wait_scan]
> [   42.254308] 
> [   42.254308] Pid: 1504, comm: kstop/0 Not tainted (2.6.32.24 #1) 
> [   42.254308] EIP: 0061:[<c102bc76>] EFLAGS: 00010002 CPU: 0
> [   42.254308] EIP is at xen_build_mfn_list_list+0x12f/0x14b
> [   42.254308] EAX: 0012d3e5 EBX: 15555000 ECX: 0012d3e5 EDX: 00000000
> [   42.254308] ESI: c18fc000 EDI: 00000000 EBP: dfccdf38 ESP: dfccdf24
> [   42.254308]  DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0069
> [   42.254308] Process kstop/0 (pid: 1504, ti=dfccc000 task=dfc5d440 task.ti=dfccc000)
> [   42.254308] Stack:
> [   42.254308]  00000000 00000000 00000000 00000003 dfccdfac dfccdf44 c102dccc 00000002
> [   42.254308] <0> dfccdf60 c12258c1 dfc53f80 00000000 c18b3438 00000003 dfccdfac dfccdf70
> [   42.254308] <0> c109b456 c2644900 c26448e8 dfccdfb8 c10761c5 00000009 dfc5d73c dfc5d440
> [   42.254308] Call Trace:
> [   42.254308]  [<c102dccc>] ? xen_post_suspend+0xb/0x7c
> [   42.254308]  [<c12258c1>] ? xen_suspend+0x9b/0xcc
> [   42.254308]  [<c109b456>] ? stop_cpu+0x7d/0xc9
> [   42.254308]  [<c10761c5>] ? worker_thread+0x15b/0x1f8
> [   42.254308]  [<c109b3d9>] ? stop_cpu+0x0/0xc9
> [   42.254308]  [<c1079313>] ? autoremove_wake_function+0x0/0x33
> [   42.254308]  [<c107606a>] ? worker_thread+0x0/0x1f8
> [   42.254308]  [<c10790cb>] ? kthread+0x61/0x66
> [   42.254308]  [<c107906a>] ? kthread+0x0/0x66
> [   42.254308]  [<c1030c97>] ? kernel_thread_helper+0x7/0x10
> [   42.254308] Code: 83 00 00 00 40 c1 e8 0c e8 cd f2 ff ff 8b 15 78 04 85 c1 8b 4d f0 89 04 8a 8b 06 05 00 00 00 40 c1 e8 0c e8 b2 f2 ff ff 
> 8b 55 ec <89> 04 93 81 c7 00 04 00 00 3b 3d b0 0d 7c c1 0f 82 29 ff ff ff 
> [   42.254308] EIP: [<c102bc76>] xen_build_mfn_list_list+0x12f/0x14b SS:ESP 0069:dfccdf24
> [   42.254308] CR2: 00000000b72050a0
> [   42.254308] ---[ end trace fd36af022f682e6b ]---
> [   42.254308] ------------[ cut here ]------------

^ permalink raw reply

* Re: [PATCH] Documentation about RS485 serial communications
From: Alexander Stein @ 2010-10-20  8:00 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Grant Edwards, linux-kernel, linux-serial
In-Reply-To: <i9kk4o$svc$1@dough.gmane.org>

On Tuesday 19 October 2010, 19:22:32 Grant Edwards wrote:
> Yes, the AT91 UARTs do have a built-in half-duplex mode that will
> automatically control line direction by toggling RTS.
> 
> That can used to control external half-duplex hardware like an RS485
> transceiver or any RS232-connected half-duplex device like some
> modems.
> 
> Though the Atmel docs refer to it as "RS485 mode" there is no RS485
> transceiver in the AT91 parts (AFAIK), and "RS485 mode" isn't specific
> to RS485 - it can be used with any external half-duplex hardware.

Out of curiosity, how can I add RS485 (or whatever) support for other serial 
devices like e.g. i.mx serial? Is there some driver independent interface 
which only gets filled in board configs like setting some GPIO pins?

Alexander

^ permalink raw reply

* Re: [PATCH hail] const-correctness tweaks
From: Jim Meyering @ 2010-10-20  8:00 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Project Hail
In-Reply-To: <4CBE1AA2.5020004@garzik.org>

Jeff Garzik wrote:

> On 10/06/2010 08:07 AM, Jim Meyering wrote:
>>
>> Make write_cb callback's buffer parameter const, like all write-like
>> functions.
>> Give a few "char *" parameters the "const" attribute.
>>
>> Signed-off-by: Jim Meyering<meyering@redhat.com>
>> ---
>>
>> It looks like most of hail's interfaces are const-correct,
>> but one stood out because it provokes a warning when I tried to
>> pass a const-correct write_cb function to hstor_get from iwhd:
>>
>>      proxy.c:382: warning: passing argument 4 of 'hstor_get' from \
>>        incompatible pointer type
>>      /usr/include/hstor.h:173: note: expected \
>>        'size_t (*)(void *, size_t, size_t,  void *)' but argument is of type \
>>        'size_t (*)(const void *, size_t,  size_t,  void *)'
>>
>> In case you feel comfortable fixing this, here's a patch:
>
>
> Sorry for not getting back to this; I had hoped to solve some
> additional problems that cropped up, but didn't have time.  So, to
> forestall further delay,
>
> libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I../include -pthread
> -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
> -I/usr/include/libxml2 -O2 -Wall -Wshadow -g -MT hutil.lo -MD -MP -MF
> .deps/hutil.Tpo -c hutil.c -o hutil.o
> hutil.c: In function ‘hreq_hdr_push’:
> hutil.c:145: warning: assignment discards qualifiers from pointer
> target type
> hutil.c:146: warning: assignment discards qualifiers from pointer
> target type
>
> warnings appear after this patch.  When solving these warnings with
> const' markers, it quickly becomes a bit of a rat's nest.
>
> At a minimum, the write_cb callback signature must match libcurl's,
> which does not use 'const'.  I can see this makes sense from libcurl
> implementation's perspective, even if it does not really match the
> constness one expects from a foo-get function.

Hi Jeff.

Sorry I didn't notice that the first time.
I built with ./autogen.sh && ./configure && make.
It looks like you recommend -Wall -Wshadow.

The two warnings above are the only ones I see with the patch,
and they're easy to fix.  When storing const pointer params into
a struct like that, I've found that it's best to cast away the "const",
which really does reflect the semantics: by using "const" on the
parameter, I view it as promising not to deref through the pointer
*in that function*.  Since it's usually not reasonable to make
the struct member "const" (as you saw, it propagates too far
and often ends up being contradictory), the lesser evil of the cast
is preferable here.

If you're still game, the following incremental patch seems to be
enough for me:  Let me know and I'll resubmit the full one.

diff --git a/lib/hutil.c b/lib/hutil.c
index 13a8d5e..b74460b 100644
--- a/lib/hutil.c
+++ b/lib/hutil.c
@@ -142,8 +142,8 @@ int hreq_hdr_push(struct http_req *req, const char *key, const char *val)
 		val++;

 	hdr = &req->hdr[req->n_hdr++];
-	hdr->key = key;
-	hdr->val = val;
+	hdr->key = (char *) key;
+	hdr->val = (char *) val;

 	return 0;
 }

^ permalink raw reply related

* [U-Boot] hi,all
From: xinrong fu @ 2010-10-20  8:00 UTC (permalink / raw)
  To: u-boot

Dear All:
A newbie post the first email.

Best Regards

^ permalink raw reply

* Re: [PATCH v2 3/3] drivers: cleanup Kconfig stuff
From: Felipe Balbi @ 2010-10-20  8:01 UTC (permalink / raw)
  To: Roger Quadros
  Cc: ext Felipe Contreras, linux-usb@vger.kernel.org, linux-omap,
	linux-main, Greg KH, Balbi, Felipe, Tony Lindgren
In-Reply-To: <4CBE9E69.6060803@nokia.com>

On Wed, Oct 20, 2010 at 02:46:49AM -0500, Roger Quadros wrote:
>On 10/19/2010 05:33 PM, ext Felipe Contreras wrote:
>> Hi Roger,
>>
>> On Tue, Oct 19, 2010 at 4:40 PM, Roger Quadros<roger.quadros@nokia.com>  wrote:
>>>> @@ -843,6 +841,7 @@ config USB_CDC_COMPOSITE
>>>>   config USB_G_NOKIA
>>>>         tristate "Nokia composite gadget"
>>>>         depends on PHONET
>>>> +       depends on USB_GADGET_MUSB_HDRC
>>>
>>> This is wrong. Is there a build problem or run-time problem without this?
>>
>> Try:
>> CONFIG_USB_G_NOKIA=y
>> CONFIG_USB_GADGET_MUSB_HDRC=n
>>
>> At least g_nokia doesn't seem to work correctly on my N900.
>>
>It won't work on N900 because N900 has MUSB USB gadget controller and
>it needs to be selected somehow while building for N900.
>
>You should set CONFIG_USB_GADGET_MUSB_HDRC to y somewhere else while
>building for N900 and not here because g_nokia is not MUSB specific.

It's the same thing I've been trying to say. No gadget driver is
controller-specific. Even though this one is called g_nokia.ko it
doesn't only Nokia can use it, neither does it mean nokia will always
use MUSB.

-- 
balbi

^ permalink raw reply

* [U-Boot] Observation: rebasing against current master increases code size by 1.8k
From: Reinhard Meyer @ 2010-10-20  8:02 UTC (permalink / raw)
  To: u-boot
In-Reply-To: <201010200342.41404.vapier@gentoo.org>

Dear Mike Frysinger,
> On Wednesday, October 20, 2010 03:30:33 Reinhard Meyer wrote:
>> Just an observation on my AT91SAM9XE based board:
>>
>> based on yesterday's master + arm elf relocations +
>> my (then not mainstreamed) patches: 256288 bytes
>>
>> based on current master: 258020 bytes
>>
>> Otherwise it compiles without warnings and runs fine.
>> Just some non-reloc-related patches have increased
>> code size by that amount - finding out which are to
>> "blame" is probably not worth the effort.
> 
> look at the env change ?
> 	ea882baf9c17cd142c99e3ff640d3ab01daa5cec

That (old) commit was in mainstream already. Related fixups
do not matter for my board since env_mmc ist not included
and ARM_RELOC_FIXUP_WORKS is set.

Reinhard

^ permalink raw reply

* RE: [PATCH/RFC v3 0/7] Videobuf2 framework
From: Hans Verkuil @ 2010-10-20  8:02 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: linux-media, pawel, kyungmin.park, mchehab
In-Reply-To: <004901cb702a$10a69100$31f3b300$%szyprowski@samsung.com>


> Hello,
>
> On Wednesday, October 20, 2010 9:15 AM wrote:
>
>> On Wednesday, October 20, 2010 08:41:06 Marek Szyprowski wrote:
>> > Hello,
>> >
>> > As I promissed I continue the development of the VideoBuf2 at Samsung
>> > until Pawel finds some spare time to help us. This is a third version
>> of
>> > the framework. Besides the minor bugfixes here and there I've added a
>> > complete read() callback emulator. This emulator provides 2 types of
>> > read() operation - 'streaming' and 'one shot'. It is suitable to
>> replace
>> > both videobuf_read_stream() and videobuf_read_one() methods from the
>> old
>> > videobuf.
>>
>> One thing I never understood: what is the point of supporting 'one shot'
>> read
>> mode? Why not support just streaming? Does anyone know?
>
> I can imagine that some simple cameras that capture pure JPG frames might
> want
> to use 'one shot' mode. This enables easier scripting and things like
> 'cat /dev/video >capture.jpg' working. If you think that 'one shot' mode
> should
> be removed - let me know.

I did a grep for videobuf_read_one in the sources and the only ones that
use it are bttv, saa7134, zr364xx, cx88 and cx23885. AFAIK zr364xx is the
only webcam driver in this set.

Mauro, do you know if there are any guidelines on what drivers are
supposed to use? Right now it seems random as to what drivers use.

The only constant I see is that vbi and compressed video (e.g. mpeg)
streaming is always using read_stream. Raw video seems to depend purely on
what the driver developer chose.

>> Another question: how hard is it to support write mode as well? I think
>> vb2 should support both. I suspect that once we have a read emulator it
>> isn't
>> difficult to make a write emulator too.
>
> Well, that's possible. If you really think that write() emulator is also
> required, I can implement both. This shouldn't be much work.

If it is not much work, then we should do that. The reason write wasn't
present before is simply that few drivers supported output streaming. But
that is changing these days so write support would definitely be a good
idea.

Regards,

        Hans


>> A last remark: the locking has changed recently in videobuf due to the
>> work
>> done on eliminating the BKL.  It's probably a good idea to incorporate
>> those
>> changes as well in vb2.
>
> Yes, I noticed that there are a lot of changes in for-2.6.37 staging tree,
> I
> will try to get through them and update relevant parts of vb2. The current
> version the vb2 patches is based on 2.6.36-rc8. Kernel tree with vb2
> patches
> (and the required multiplane patches) will be available in a few hours on:
>
> http://git.infradead.org/users/kmpark/linux-2.6-samsung/shortlog/refs/heads/v4l/vb2
>
> Best regards
> --
> Marek Szyprowski
> Samsung Poland R&D Center
>
>


-- 
Hans Verkuil - video4linux developer - sponsored by TANDBERG, part of Cisco


^ permalink raw reply


This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.