LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Userspace - Kernel Space "Connector" test
@ 2008-03-26 10:11 Midhun A
  2008-03-27 14:38 ` Evgeniy Polyakov
  0 siblings, 1 reply; 7+ messages in thread
From: Midhun A @ 2008-03-26 10:11 UTC (permalink / raw)
  To: linux-kernel

Hi All,

   I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
space to User space communication.  My kernel version is 2.6.22.
Before using it, I am trying out the example programs in the
Documentation folder. I have cn_test.c built into the kernel (not
loaded as a module) and I have compiled ucon.c.

When I run ucon, the programs hangs at the point it polls the socket.

	while (!need_exit) {

		printf("Entered While\n");	
		pfd.events = POLLIN;
		printf("1\n");
		pfd.revents = 0;
		printf("1.1\n");		
->	      switch (poll(&pfd, 1, -1)) {

The source code is the same as in the kernel/Documentation/Connector folder.

How do I get to know whether it is listening to the same socket as
cn_test is sending message on?

Thanks,
Midhun.


P.S.: I am not subscribed to the list. Please CC me.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-03-26 10:11 Userspace - Kernel Space "Connector" test Midhun A
@ 2008-03-27 14:38 ` Evgeniy Polyakov
  2008-04-04  7:01   ` Midhun A
  0 siblings, 1 reply; 7+ messages in thread
From: Evgeniy Polyakov @ 2008-03-27 14:38 UTC (permalink / raw)
  To: Midhun A; +Cc: linux-kernel

Hi.

On Wed, Mar 26, 2008 at 03:41:16PM +0530, Midhun A (midhunagni@gmail.com) wrote:
>    I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
> space to User space communication.  My kernel version is 2.6.22.
> Before using it, I am trying out the example programs in the
> Documentation folder. I have cn_test.c built into the kernel (not
> loaded as a module) and I have compiled ucon.c.

You have to use smaller index than 32 or increase CN_NETLINK_USERS
parameter in include/linux/connector.h

Currently all kernel users fit that limitation, which is ok.

Also, parameter used in bind() is a bitmap of requested groups, to
listen on 0x123 idx you have to add it via setsockopt(), which is
commented in ucon.c.

So, either switch to smaller group number (connector index) or increase
above limit. If you will select the former case (it is simpler from
userspace point of view), you have to change bind() group, note that it
is a bitmap, os group N equals to (1<<N) bind() value. If you will
select the latter case and recompile connector module, then you have to
uncomment setsockopt() code in ucon.c

Both methods work, and you will get something like this:
$ sudo ./ucon
Thu Mar 27 17:29:19 2008 : [123.457] [00000002.00000000].
Thu Mar 27 17:29:20 2008 : [123.457] [00000003.00000000].
Thu Mar 27 17:29:21 2008 : [123.457] [00000004.00000000].
Thu Mar 27 17:29:22 2008 : [123.457] [00000005.00000000].
Thu Mar 27 17:29:23 2008 : [123.457] [00000006.00000000].

-- 
	Evgeniy Polyakov

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-03-27 14:38 ` Evgeniy Polyakov
@ 2008-04-04  7:01   ` Midhun A
  2008-04-21 10:29     ` Midhun A
  0 siblings, 1 reply; 7+ messages in thread
From: Midhun A @ 2008-04-04  7:01 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: linux-kernel

Hey,

  Thanks a lot. I have changed the idx value to 7 and it worked. :)

Thanks,
Midhun

On Thu, Mar 27, 2008 at 8:08 PM, Evgeniy Polyakov <johnpol@2ka.mipt.ru> wrote:
> Hi.
>
>
>  On Wed, Mar 26, 2008 at 03:41:16PM +0530, Midhun A (midhunagni@gmail.com) wrote:
>  >    I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
>  > space to User space communication.  My kernel version is 2.6.22.
>  > Before using it, I am trying out the example programs in the
>  > Documentation folder. I have cn_test.c built into the kernel (not
>  > loaded as a module) and I have compiled ucon.c.
>
>  You have to use smaller index than 32 or increase CN_NETLINK_USERS
>  parameter in include/linux/connector.h
>
>  Currently all kernel users fit that limitation, which is ok.
>
>  Also, parameter used in bind() is a bitmap of requested groups, to
>  listen on 0x123 idx you have to add it via setsockopt(), which is
>  commented in ucon.c.
>
>  So, either switch to smaller group number (connector index) or increase
>  above limit. If you will select the former case (it is simpler from
>  userspace point of view), you have to change bind() group, note that it
>  is a bitmap, os group N equals to (1<<N) bind() value. If you will
>  select the latter case and recompile connector module, then you have to
>  uncomment setsockopt() code in ucon.c
>
>  Both methods work, and you will get something like this:
>  $ sudo ./ucon
>  Thu Mar 27 17:29:19 2008 : [123.457] [00000002.00000000].
>  Thu Mar 27 17:29:20 2008 : [123.457] [00000003.00000000].
>  Thu Mar 27 17:29:21 2008 : [123.457] [00000004.00000000].
>  Thu Mar 27 17:29:22 2008 : [123.457] [00000005.00000000].
>  Thu Mar 27 17:29:23 2008 : [123.457] [00000006.00000000].
>
>  --
>         Evgeniy Polyakov
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-04-04  7:01   ` Midhun A
@ 2008-04-21 10:29     ` Midhun A
  2008-04-21 10:43       ` Evgeniy Polyakov
  0 siblings, 1 reply; 7+ messages in thread
From: Midhun A @ 2008-04-21 10:29 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: linux-kernel

Hi,

   I now want to use "connector" inside the MMC host module. The aim
is to get a notification to the userspace when the MMC/SD card is
inserted. I have put the code of the connector module (kernel side)
inside imxmmc.c (ernel version 2.6.22). I am running ucon to receive
the message. The kernel module seems to send the message but ucon is
not able to receive the message. The snipped code is as follows:

#include <linux/connector.h>

static struct cb_id cn_test_id = { 0x7, 0x7 };
static u32 cn_test_timer_counter;

/* The card detector method */
static void imxmci_check_status(unsigned long data)
{
	struct imxmci_host *host = (struct imxmci_host *)data;

	/*Netlink*/
	struct cn_msg *m;
	char cn_data[32] = "SD/MMC Card Status";
	/*Netlink*/

	if( host->pdata->card_present() != host->present ) {
		host->present ^= 1;
		dev_info(mmc_dev(host->mmc), "card %s\n",
		      host->present ? "inserted" : "removed");

	/*Netlink*/

	m = kmalloc(sizeof(*m) + sizeof(cn_data), GFP_ATOMIC);

	if (m) {
		printk("Inside if\n");
		memset(m, 0, sizeof(*m) + sizeof(cn_data));
		memcpy(&m->id, &cn_test_id, sizeof(m->id));
		m->seq = cn_test_timer_counter;
		m->len = sizeof(cn_data);

		m->len =
		    scnprintf(cn_data, sizeof(cn_data), "counter = %u",
			      cn_test_timer_counter) + 1;

		memcpy(m + 1, data, m->len);
		printk("Copied Message\n");		
		cn_netlink_send(m, 0, gfp_any());
		printk("Sent Message\n");		
		kfree(m);
	}
	else
	{
		printk("Memory issue with m\n");
	}			
		cn_test_timer_counter++;

	/*Netlink*/

		set_bit(IMXMCI_PEND_CARD_XCHG_b, &host->pending_events);
		tasklet_schedule(&host->tasklet);
	}

	if(test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events) ||
	   test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) {
		atomic_inc(&host->stuck_timeout);
		if(atomic_read(&host->stuck_timeout) > 4)
			tasklet_schedule(&host->tasklet);
	} else {
		atomic_set(&host->stuck_timeout, 0);

	}

	mod_timer(&host->timer, jiffies + (HZ>>1));
}

I keep the ucon program running. As soon as I insert the card, the
kernel detects that the card is inserted and the printks say that the
message has sent. But ucon does not receive the message.

Any kind of help would be useful.

Thanks,
Midhun.


On 4/4/08, Midhun A <midhunagni@gmail.com> wrote:
> Hey,
>
>   Thanks a lot. I have changed the idx value to 7 and it worked. :)
>
> Thanks,
> Midhun
>
> On Thu, Mar 27, 2008 at 8:08 PM, Evgeniy Polyakov <johnpol@2ka.mipt.ru>
> wrote:
> > Hi.
> >
> >
> >  On Wed, Mar 26, 2008 at 03:41:16PM +0530, Midhun A (midhunagni@gmail.com)
> wrote:
> >  >    I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
> >  > space to User space communication.  My kernel version is 2.6.22.
> >  > Before using it, I am trying out the example programs in the
> >  > Documentation folder. I have cn_test.c built into the kernel (not
> >  > loaded as a module) and I have compiled ucon.c.
> >
> >  You have to use smaller index than 32 or increase CN_NETLINK_USERS
> >  parameter in include/linux/connector.h
> >
> >  Currently all kernel users fit that limitation, which is ok.
> >
> >  Also, parameter used in bind() is a bitmap of requested groups, to
> >  listen on 0x123 idx you have to add it via setsockopt(), which is
> >  commented in ucon.c.
> >
> >  So, either switch to smaller group number (connector index) or increase
> >  above limit. If you will select the former case (it is simpler from
> >  userspace point of view), you have to change bind() group, note that it
> >  is a bitmap, os group N equals to (1<<N) bind() value. If you will
> >  select the latter case and recompile connector module, then you have to
> >  uncomment setsockopt() code in ucon.c
> >
> >  Both methods work, and you will get something like this:
> >  $ sudo ./ucon
> >  Thu Mar 27 17:29:19 2008 : [123.457] [00000002.00000000].
> >  Thu Mar 27 17:29:20 2008 : [123.457] [00000003.00000000].
> >  Thu Mar 27 17:29:21 2008 : [123.457] [00000004.00000000].
> >  Thu Mar 27 17:29:22 2008 : [123.457] [00000005.00000000].
> >  Thu Mar 27 17:29:23 2008 : [123.457] [00000006.00000000].
> >
> >  --
> >         Evgeniy Polyakov
> >
>


-- 
Midhun.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-04-21 10:29     ` Midhun A
@ 2008-04-21 10:43       ` Evgeniy Polyakov
  2008-04-23  8:19         ` Midhun A
  0 siblings, 1 reply; 7+ messages in thread
From: Evgeniy Polyakov @ 2008-04-21 10:43 UTC (permalink / raw)
  To: Midhun A; +Cc: linux-kernel

Hi.

On Mon, Apr 21, 2008 at 03:59:32PM +0530, Midhun A (midhunagni@gmail.com) wrote:
> static void imxmci_check_status(unsigned long data)
> {
> 	struct imxmci_host *host = (struct imxmci_host *)data;
> 
> 	/*Netlink*/
> 	struct cn_msg *m;
> 	char cn_data[32] = "SD/MMC Card Status";
> 	/*Netlink*/
> 
> 	if( host->pdata->card_present() != host->present ) {
> 		host->present ^= 1;
> 		dev_info(mmc_dev(host->mmc), "card %s\n",
> 		      host->present ? "inserted" : "removed");
> 
> 	/*Netlink*/
> 
> 	m = kmalloc(sizeof(*m) + sizeof(cn_data), GFP_ATOMIC);
> 
> 	if (m) {
> 		printk("Inside if\n");
> 		memset(m, 0, sizeof(*m) + sizeof(cn_data));
> 		memcpy(&m->id, &cn_test_id, sizeof(m->id));
> 		m->seq = cn_test_timer_counter;
> 		m->len = sizeof(cn_data);
> 
> 		m->len =
> 		    scnprintf(cn_data, sizeof(cn_data), "counter = %u",
> 			      cn_test_timer_counter) + 1;
> 
> 		memcpy(m + 1, data, m->len);
> 		printk("Copied Message\n");		
> 		cn_netlink_send(m, 0, gfp_any());
> 		printk("Sent Message\n");		
> 		kfree(m);

What is return value here?
Also, do you register this driver as connector user? If not, you can not
use 0 group number, since it will search only for registered kernel
side, and if there was no registration, it can not obtain address of the
userspace side. You can specify group (7 in your cae) as a parameter
instead.

I suppose userspace was bound to (1<<7) group number or was subscribed
using socket option to 7'th group.

-- 
	Evgeniy Polyakov

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-04-21 10:43       ` Evgeniy Polyakov
@ 2008-04-23  8:19         ` Midhun A
  2008-04-23  8:33           ` Evgeniy Polyakov
  0 siblings, 1 reply; 7+ messages in thread
From: Midhun A @ 2008-04-23  8:19 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: linux-kernel

Hey,

I had changed the group number. It worked ! Thanks a lot for the help
and also also the code !

Regards,
Midhun

On Mon, Apr 21, 2008 at 4:13 PM, Evgeniy Polyakov <johnpol@2ka.mipt.ru> wrote:
> Hi.
>
>
>
>  On Mon, Apr 21, 2008 at 03:59:32PM +0530, Midhun A (midhunagni@gmail.com) wrote:
>  > static void imxmci_check_status(unsigned long data)
>  > {
>  >       struct imxmci_host *host = (struct imxmci_host *)data;
>  >
>  >       /*Netlink*/
>  >       struct cn_msg *m;
>  >       char cn_data[32] = "SD/MMC Card Status";
>  >       /*Netlink*/
>  >
>  >       if( host->pdata->card_present() != host->present ) {
>  >               host->present ^= 1;
>  >               dev_info(mmc_dev(host->mmc), "card %s\n",
>  >                     host->present ? "inserted" : "removed");
>  >
>  >       /*Netlink*/
>  >
>  >       m = kmalloc(sizeof(*m) + sizeof(cn_data), GFP_ATOMIC);
>  >
>  >       if (m) {
>  >               printk("Inside if\n");
>  >               memset(m, 0, sizeof(*m) + sizeof(cn_data));
>  >               memcpy(&m->id, &cn_test_id, sizeof(m->id));
>  >               m->seq = cn_test_timer_counter;
>  >               m->len = sizeof(cn_data);
>  >
>  >               m->len =
>  >                   scnprintf(cn_data, sizeof(cn_data), "counter = %u",
>  >                             cn_test_timer_counter) + 1;
>  >
>  >               memcpy(m + 1, data, m->len);
>  >               printk("Copied Message\n");
>  >               cn_netlink_send(m, 0, gfp_any());
>  >               printk("Sent Message\n");
>  >               kfree(m);
>
>  What is return value here?
>  Also, do you register this driver as connector user? If not, you can not
>  use 0 group number, since it will search only for registered kernel
>  side, and if there was no registration, it can not obtain address of the
>  userspace side. You can specify group (7 in your cae) as a parameter
>  instead.
>
>  I suppose userspace was bound to (1<<7) group number or was subscribed
>  using socket option to 7'th group.
>
>  --
>         Evgeniy Polyakov
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Userspace - Kernel Space "Connector" test
  2008-04-23  8:19         ` Midhun A
@ 2008-04-23  8:33           ` Evgeniy Polyakov
  0 siblings, 0 replies; 7+ messages in thread
From: Evgeniy Polyakov @ 2008-04-23  8:33 UTC (permalink / raw)
  To: Midhun A; +Cc: linux-kernel

Hi.

On Wed, Apr 23, 2008 at 01:49:46PM +0530, Midhun A (midhunagni@gmail.com) wrote:
> I had changed the group number. It worked ! Thanks a lot for the help
> and also also the code !

You are welcome :)

-- 
	Evgeniy Polyakov

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-04-23  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-26 10:11 Userspace - Kernel Space "Connector" test Midhun A
2008-03-27 14:38 ` Evgeniy Polyakov
2008-04-04  7:01   ` Midhun A
2008-04-21 10:29     ` Midhun A
2008-04-21 10:43       ` Evgeniy Polyakov
2008-04-23  8:19         ` Midhun A
2008-04-23  8:33           ` Evgeniy Polyakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).