allready defined in sdp_lib.h
[xkbdbthid.git] / bthid / xkbdbthidwrapper / xkbdbthidwrapper.c
1 /*
2  *  xkbd-bthid-wrapper (for Nokia770)
3  *
4  *  (c) Collin R. Mulliner <collin@betaversion.net>
5  *  http://www.mulliner.org/nokia770/
6  * 
7  *  License: GPL
8  * 
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #define USAGE "\nxkbd-bthid-wrapper is wrapper for xkbd-bthid\n"\
16               " it reconfigures the hci0 device to be usable as a keyboard\n"\
17               " and also starts the sdpd service, to do this it needs to run with\n"\
18               " root privileges. these will be dropped before executing xkbd-bthid\n"\
19               " also the hci0 settings will be reverted to default values on exit\n"
20
21 int main(int argc, char **argv)
22 {
23         int pid, status;
24                                 
25         if (geteuid() != 0) {
26                 fprintf(stderr, "%s: needs root privileges\n", argv[0]);
27                 fprintf(stderr, USAGE);
28                 exit(-1);
29         }
30         else {
31                 if ((pid = fork())) {
32                         waitpid(pid, &status, 0);
33                 }
34                 else {
35                         execl("/usr/sbin/hciconfig", "hciconfig", "hci0", "piscan");
36                 }
37                 if ((pid = fork())) {
38                         waitpid(pid, &status, 0);
39                 }
40                 else {
41                         execl("/usr/sbin/hciconfig", "hciconfig", "hci0", "class", "0x002540");
42                 }
43                 if ((pid = fork())) {
44                         waitpid(pid, &status, 0);
45                 }
46                 else {
47                         execl("/usr/sbin/sdpd", "sdpd");
48                 }
49
50                 if ((pid = fork())) {
51                         waitpid(pid, &status, 0);
52
53                         if ((pid = fork())) {
54                                 waitpid(pid, &status, 0);
55                         }
56                         else {
57                                 execl("/usr/sbin/hciconfig", "hciconfig", "hci0", "pscan");
58                         }
59                         if ((pid = fork())) {
60                                 waitpid(pid, &status, 0);
61                         }
62                         else {
63                                 execl("/usr/sbin/hciconfig", "hciconfig", "hci0", "class", "0x00100");
64                         }
65                 }
66                 else {
67                         setegid(getgid());
68                         seteuid(getuid());
69                         execl("/var/lib/install/usr/bin/xkbdbthid", "xkbdbthid", argv[1], argv[2]);
70                         exit(0);
71                 }
72         }
73 }