LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-25-2011, 01:29 PM   #1
psmurthy
LQ Newbie
 
Registered: Mar 2010
Posts: 11

Rep: Reputation: 0
How to register user space call back function with USB driver in Linux?


Hi,
Can anybody tell me how to register user space call back function with USB driver? In call back function i would like to do some checks from user space.
Regards,
Murthy
 
Old 08-25-2011, 10:10 PM   #2
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
I have no idea how to do what you want but in order for others to help you please post the output of the following commands:
lsusb
--which gives information about your usb devices,
lsmod
--which gives a list of all loaded drivers.
When the pertinent loaded drivers are found running:
modinfo driver
The last command should tell you what options for the driver are available. Maybe someone else can help you from there. Good luck.
 
Old 09-04-2011, 01:10 AM   #3
psmurthy
LQ Newbie
 
Registered: Mar 2010
Posts: 11

Original Poster
Rep: Reputation: 0
using netlink socket to get uevents on usb insert/remove in Linux

Hi .. I did little research and came to know we can get uevents from linux kernek on device insert/remove over netlink sockets.My question is now,How to get uevents to my user space task on USB insert/remove using netlink sockets.
I got piece of code in web. I modified it little bit and ran.
But it is not working.Here is the code.
Code:
#include <sys/socket.h>
#include <linux/netlink.h>
#include <stdio.h>
struct sockaddr_nl src_addr, dest_addr;  
struct nlmsghdr *nlh = NULL;  
struct iovec iov;  
struct msghdr msg;  
int sock_fd;  
void main() {

sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ISCSI);  
if(sock_fd < 0)  
printf("Socket creatioin failed\n");  

 else  
  printf("soscet created succfully\n");  

 memset(&src_addr, 0, sizeof(src_addr));  
 src_addr.nl_family = AF_NETLINK;  
 src_addr.nl_pid = getpid();  /* self pid */  
 src_addr.nl_groups = 0;  /* not in mcast groups */  

 if(bind(sock_fd, (struct sockaddr*)&src_addr,sizeof(src_addr)) < 0)  
  printf("bind Error\n");  
 else  
  printf("Bind Successful\n");  

 memset(&dest_addr, 0, sizeof(dest_addr));  
 dest_addr.nl_family = AF_NETLINK;  
 dest_addr.nl_pid = 0;   /* For Linux Kernel */  
 dest_addr.nl_groups = 0; /* unicast */  

 nlh=(struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));  

 /* Fill the netlink message header */  
 nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);  
 nlh->nlmsg_pid = getpid();  /* self pid */  
 nlh->nlmsg_flags = 0;  

 /* Fill in the netlink message payload */  
 strcpy(NLMSG_DATA(nlh), "Hello you!");  

 iov.iov_base = (void *)nlh;  
 iov.iov_len = nlh->nlmsg_len;  

 msg.msg_name = (void *)&dest_addr;  
 msg.msg_namelen = sizeof(dest_addr);  
 msg.msg_iov = &iov;  
 msg.msg_iovlen = 20;  

 // sendmsg(sock_fd, &msg, 0);  

 /* Read message from kernel */  
 memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD));  
 printf("%s %d\n",__FILE__,__LINE__);  
 recvmsg(sock_fd, &msg, 0);  
 printf("%s %d\n",__FILE__,__LINE__);  
 printf("Received message payload: %s\n",(char *)NLMSG_DATA(nlh));  

 /* Close Netlink Socket */  
 close(sock_fd);  
}
I tested it in following way
1.Start the above program
2.Insert an USB disk.
expected behavior: messages should come on to console
actual behavior: i didn't see any messages and program blocked at "recvmsg"
as it is not receiving any messages from kernel.
Appreciate your help

Regards,
Ramji

Last edited by psmurthy; 09-05-2011 at 01:05 AM.
 
Old 09-04-2011, 10:56 AM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Welcome to LQ. Hope your time here helps you as much as mine has helped me.

Please put code, command line output, config files, etc. inside [CODE] tags, aka "Code:" blocks.
There are 2 ways to generate "Code:" tags:
  1. You can simply type them yourself -- "[code] ... [/code]". (They are not case sensitive.)

  2. You can also click on the '#' icon above the text entry window. If you highlight the code before you click the '#' icon, your code, command line output, config files, etc. will get put inside a "Code:" block. The '#' icon is available when you start your post by clicking the "Post Reply" button or the "Go Advanced" button; it is not currenetly available in the Quick Reply window.

They will make your posts easier to read, & that will get you more, faster, better answers. -- Help us help you.
BTW, You can edit your post(s) to do this retroactively. Please do so soon.

Thank you, & again, welcome.

---------- Post added 09-04-11 at 10:56 AM ----------

Moved: This thread is more suitable in Kernel and has been moved accordingly to help your thread/question get the exposure it deserves.

Last edited by archtoad6; 09-04-2011 at 11:06 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what Kernel do if user call malloc() function in user space? rsyoung Linux - Kernel 5 03-26-2014 06:09 PM
what Kernel do if user call malloc() function in user space? rsyoung Linux - Newbie 1 06-20-2009 11:40 AM
USB driver won't call probe function linux=future Linux - Kernel 2 01-13-2007 04:47 PM
can interrupt handler call user space function? pot_po Programming 0 11-07-2002 09:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration