diff --git a/src/gpm2/Makefile b/src/gpm2/Makefile new file mode 100644 index 0000000..6b8ac78 --- /dev/null +++ b/src/gpm2/Makefile @@ -0,0 +1,136 @@ +# +# cinit +# +# Nico Schottelius +# +# Don't edit Makefiles, use conf/* for configuration. +# + +#include Makefile.tests + +# Build tools / locations +CC=./tmp/cc +CFLAGS= +LD=./tmp/ld +LDFLAGS= +STRIP=./tmp/strip +SBIN=../sbin + +# directories and files +CONFIG_H=include/config.h + +BIN=cinit + +# +# End user targets +# +all: out/gpm2-daemon + + +# +# All objects depend on headers. +# +GPM2_DAEMON_HEADERS=$(shell cat deps/gpm2-daemon-headers) + + +# +# Objects +# + +GPM2_DAEMON_OBJECTS=$(shell cat deps/gpm2-daemon) +$(GPM2_DAEMON_OBJECTS): $(GPM2_DAEMON_HEADERS) + +GPM2_DAEMON_PROTOCOLS=$(shell cat tmp/protocol-deps) + +CLIENT= + +COMMUNICATION= + +OBJ= + +# +# Programs +# + +out/gpm2-daemon: $(GPM2_DAEMON_OBJECTS) $(GPM2_DAEMON_PROTOCOLS) + $(LD) -o $@ $^ + + +# +# Generic +# + +%.o: %.c .configured + $(CC) -c -o $@ $< + + + +# +# First do configuration, so we include the right variables +# +Makefile: .configured + +.configured: conf/* + @./scripts/generate_cbuiltconfig.sh conf + +$(CINIT_OBJ): $(CONFIG_H) + + +$(CONFIG_H): ../conf/* + ../scripts/cinit.mkheader > $(CONFIG_H) + +cservice: $(SBIN)/cservice + +$(SBIN)/cservice util/cservice: $(SBIN) $(CSVC_OBJ) + $(LD) $(LDFLAGS) $(CSVC_OBJ) -o $@ + $(STRIP) $@ + +ccontrol: $(SBIN)/ccontrol + +$(SBIN)/ccontrol util/ccontrol: config.h $(SBIN) $(CCO_OBJ) + $(LD) $(LDFLAGS) $(CCO_OBJ) -o $@ + $(STRIP) $@ + +install: install-dir cinit cservice ccontrol + @echo '*** Installing cinit ***' + ./bin/cinit.install.binary + +install-miniconf: + ./bin/cinit.install.miniconf + +install-dir: + ./bin/cinit.install.dir + + +################################################################################ +# +# Build targets +# +cinit: $(CINIT_OBJ) + $(LD) $^ -o $@ + +uml: cinit + ../../vm/uml/uml-mount.sh + cp cinit ../../vm/uml/root/sbin/cinit + ../../vm/uml/uml-umount.sh + +umlstart: uml + ../../vm/uml/uml-start.sh + +################################################################################ +# +# Generic targets +# + +.PHONY: dist +dist: distclean + +.PHONY: distclean +distclean: clean + rm -f os/current ipc/current .configured + +.PHONY: clean +clean: + rm -f ../tmpbin/*.configured + rm -f $(BIN) $(CINIT_OBJ) + rm -f test/*.o diff --git a/src/gpm2/TODO b/src/gpm2/TODO new file mode 100644 index 0000000..bc1b3a8 --- /dev/null +++ b/src/gpm2/TODO @@ -0,0 +1,4 @@ +- read cconfig-directory +- create mouse structures +- use cconfig-protocol-options as base for each protocol + char *fullpath? diff --git a/src/gpm2/client/README b/src/gpm2/client/README new file mode 100644 index 0000000..7da4b23 --- /dev/null +++ b/src/gpm2/client/README @@ -0,0 +1,18 @@ +The files in this directory should built up the client interface. + +Some ideas: + + struct gpm2_conn *gpm2_connect(): + client connects to gpm2-daemon + + gpm2_get_mice(struct gpm2_conn *g2c): + get list of devices, including protocols and ids + + struct *mouseinfo gpm2_open_mouse(int mouse_id, int type); + returns set of descriptors: + - to read mousedata + + int gpm2_close_mouse(struct *mouseinfo mi); + + + diff --git a/src/gpm2/conf/README b/src/gpm2/conf/README new file mode 100644 index 0000000..788196a --- /dev/null +++ b/src/gpm2/conf/README @@ -0,0 +1,11 @@ +This is the conf/ directory Nico Schottelius uses to configure his +software projects. They evolve with every project and the aim is +to replace autoconf once. + +In general, the idea is to create extremly simply configuration files, +that are editable by non-interactive programs (distributor friendly). + +In most cases only the first line is important and the other lines are +simply the description. + + programs/ - contains definitions of programs we need in our built process diff --git a/src/gpm2/conf/built-options/protocols b/src/gpm2/conf/built-options/protocols new file mode 100644 index 0000000..6857e18 --- /dev/null +++ b/src/gpm2/conf/built-options/protocols @@ -0,0 +1,3 @@ +ps2 + +List of protocols to enable (at built time: not expandable later). diff --git a/src/gpm2/conf/built/ld b/src/gpm2/conf/built/ld new file mode 100644 index 0000000..aa323fc --- /dev/null +++ b/src/gpm2/conf/built/ld @@ -0,0 +1,3 @@ +gcc + +The program used to link diff --git a/src/gpm2/conf/programs/cc b/src/gpm2/conf/programs/cc new file mode 100644 index 0000000..b168ae6 --- /dev/null +++ b/src/gpm2/conf/programs/cc @@ -0,0 +1,3 @@ +gcc + +The c-compiler to use. diff --git a/src/gpm2/conf/programs/cc.params b/src/gpm2/conf/programs/cc.params new file mode 100644 index 0000000..3e5f99a --- /dev/null +++ b/src/gpm2/conf/programs/cc.params @@ -0,0 +1,3 @@ +-pipe -W -Wall -Werror -I. -Iinclude -g + +flags to pass to the c-compiler. diff --git a/src/gpm2/conf/programs/ld b/src/gpm2/conf/programs/ld new file mode 100644 index 0000000..7121e83 --- /dev/null +++ b/src/gpm2/conf/programs/ld @@ -0,0 +1,3 @@ +gcc + +The linker to use. diff --git a/src/gpm2/core/main.c b/src/gpm2/core/main.c new file mode 100644 index 0000000..7109e48 --- /dev/null +++ b/src/gpm2/core/main.c @@ -0,0 +1,44 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * main: Where life of gpm2 begins. + ********/ + + +#include "gpm2-daemon.h" + +int main(int argc, char **argv) +{ + set_defaults(); + + if(!commandline(argc,argv)) return 1; + + if(!read_config(opts.cconfig)) return 1; + + /* creates a fork() */ + if(!mice_handler()) return 1; + + /* listen to messages: exits only on failure or shutdown */ +// listen_ipc(); + +// shutdown_gpm2(); + + return 0; +} diff --git a/src/gpm2/core/read_config.c b/src/gpm2/core/read_config.c new file mode 100644 index 0000000..05e3cc2 --- /dev/null +++ b/src/gpm2/core/read_config.c @@ -0,0 +1,34 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * read cconfig + ********/ + +#include "gpm2-daemon.h" + +int read_config(char *cconfig) +{ + /* open cconfig-dir (FIXME: write small framework for reuse) */ + + if(!cconfig) return 0; /* remove, just to make gcc happy */ + /* set options */ + + return 1; +} diff --git a/src/gpm2/core/set_defaults.c b/src/gpm2/core/set_defaults.c new file mode 100644 index 0000000..0b840c0 --- /dev/null +++ b/src/gpm2/core/set_defaults.c @@ -0,0 +1,31 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * set the default options + ********/ + + +#include "gpm2-daemon.h" + +void set_defaults() +{ + /* options */ + opts.cconfig = GPM2_CCONFIG; +} diff --git a/src/gpm2/deps/gpm2-daemon b/src/gpm2/deps/gpm2-daemon new file mode 100644 index 0000000..31e1fbe --- /dev/null +++ b/src/gpm2/deps/gpm2-daemon @@ -0,0 +1,7 @@ +core/main.o +core/read_config.o +core/set_defaults.o +generic/commandline.o +generic/daemon-usage.o +generic/mini_printf.o +mice/mice_handler.o diff --git a/src/gpm2/deps/gpm2-daemon-headers b/src/gpm2/deps/gpm2-daemon-headers new file mode 100644 index 0000000..d79ea81 --- /dev/null +++ b/src/gpm2/deps/gpm2-daemon-headers @@ -0,0 +1 @@ +include/gpm2-daemon.h diff --git a/src/gpm2/doc/CONFIGURATION b/src/gpm2/doc/CONFIGURATION new file mode 100644 index 0000000..1ae0fe2 --- /dev/null +++ b/src/gpm2/doc/CONFIGURATION @@ -0,0 +1,17 @@ +Configuration: + /etc/gpm2/ + mice/ + default/ + mice-userid: userid of person reading/writing mice devices + mice-groupid: groupid of person reading/writing mice devices + + / + device: link or device to use + protocol: one line, containing protocol + userid: overwrites default/mice-userid + groupid: overwrites default/mice-groupid + options/: options for that protocol + + + + clients/ diff --git a/src/gpm2/doc/DESIGN b/src/gpm2/doc/DESIGN new file mode 100644 index 0000000..732f9d3 --- /dev/null +++ b/src/gpm2/doc/DESIGN @@ -0,0 +1,65 @@ +Possible design of gpm2: + + gpm2-starter: + - reads configuration + - starts daemons + * first gpm2-daemon + - connects daemons + * connects them through stdin and stdout? + - perhaps a job of gpm2-daemon? + * stderr is relayed to the log console + - which can log to syslog + + gpm2-daemon: + - main daemon + - starts mice handlers + - listens for ipc + - relays input data abstracted to clients + - does *NOT* draw a cursor or something like that + - can be used by x.org (see below) + - opens mice devices? + - should be portable + + gpm2-io: + - gets list of opened fds or of devices + - uses poll() / select() on mice devices + - retrieves data packets + - forwards raw data packets to gpm2-daemon from devices + - either + - forwards raw data packets from gpm2-daemon to devices?? + - decodes mice packets: does protocol handling and + forwards decoded packages to gpm2_daemon + - has a mouse - fd_in - fd_out list + - has *NO* root priviliges + + gpm2-decode: + - forwards raw data packets from gpm2-daemon + - forwards decoded packages to clients (like gpm2-cdisplay) + + gpm2-raw-relay: + - reads data from gpm2-daemon + - writes raw data to clients + - a client needs to connect n times for n mice + + gpm2-cdisplay: + - Console DISPLAYS: displays mouse cursor on console + - reads input from gpm2-daemon + - reads mouse information + - perhaps os-specific versions + + gpm2-ccandp: + - Console Copy AND Paste daemon + - reads input from gpm2-daemon + - copies selected text into own buffer + - pastes buffer to console + - perhaps os-specific versions + + gpm2-xorg: + - interface between gpm2 and x.org + - could make mouse support unecessary in x.org + - should be portable + + gpm2-syslog: + - connects to the gpm2-daemon logging port + - reads messages + - relays them to syslog diff --git a/src/gpm2/generic/commandline.c b/src/gpm2/generic/commandline.c new file mode 100644 index 0000000..76f6498 --- /dev/null +++ b/src/gpm2/generic/commandline.c @@ -0,0 +1,42 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * handle command line arguments + ********/ + +#include /* getopt() */ + +#include "gpm2-daemon.h" + +int commandline(int argc, char **argv) +{ + int opt; + + while((opt = getopt(argc,argv,GPM2_ARGS)) != -1) { + switch(opt) { + default: + usage(); + break; + } + + } + + return 1; +} diff --git a/src/gpm2/generic/daemon-usage.c b/src/gpm2/generic/daemon-usage.c new file mode 100644 index 0000000..e5ec067 --- /dev/null +++ b/src/gpm2/generic/daemon-usage.c @@ -0,0 +1,32 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * Print out, how to use gpm2-daemon + ********/ + +#include "gpm2-generic.h" + +void usage() +{ + mini_printf("gpm2-daemon: written by Nico Schottelius\n",1); + mini_printf("\n",1); + mini_printf(" -c : specify configuration directory\n",1); + mini_printf(" -f: fork into background after startup \n",1); +} diff --git a/src/gpm2/generic/mini_printf.c b/src/gpm2/generic/mini_printf.c new file mode 100644 index 0000000..d5b0d1f --- /dev/null +++ b/src/gpm2/generic/mini_printf.c @@ -0,0 +1,24 @@ +/*********************************************************************** + * + * 2005-2007 Nico Schottelius (nico-cinit at schottelius.org) + * + * part of cLinux/cinit + * + * Print the world! + * + */ + +#include + +void mini_printf(char *str,int fd) +{ + char *p; + + /* don't get fooled by bad pointers */ + if(str == NULL) return; + + p = str; + while(*p) p++; + + write(fd,str,(size_t) (p - str)); +} diff --git a/src/gpm2/generic/read_packet.c b/src/gpm2/generic/read_packet.c new file mode 100644 index 0000000..cb5285d --- /dev/null +++ b/src/gpm2/generic/read_packet.c @@ -0,0 +1,44 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * read one mouse packet and return it + ********/ + +#include /* read() */ +#include /* NULL */ +#include /* malloc() */ +#include /* errno */ + +char *read_packet(int fd, int len) +{ + char *packet; + + errno = 0; /* no library function ever sets errno to 0, so we do */ + + packet = malloc(len); + if(packet == NULL) return NULL; + + if(read(fd,&packet,len) == -1) { + free(packet); + return NULL; + } + + return packet; +} diff --git a/src/gpm2/include/gpm2-client.h b/src/gpm2/include/gpm2-client.h new file mode 100644 index 0000000..b7857bc --- /dev/null +++ b/src/gpm2/include/gpm2-client.h @@ -0,0 +1,28 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * client information + ********/ + +/* functions */ + + + + diff --git a/src/gpm2/include/gpm2-config.h b/src/gpm2/include/gpm2-config.h new file mode 100644 index 0000000..af6788c --- /dev/null +++ b/src/gpm2/include/gpm2-config.h @@ -0,0 +1,24 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * values shared by daemon and clients + ********/ + + diff --git a/src/gpm2/include/gpm2-daemon.h b/src/gpm2/include/gpm2-daemon.h new file mode 100644 index 0000000..3521ad3 --- /dev/null +++ b/src/gpm2/include/gpm2-daemon.h @@ -0,0 +1,50 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * daemon specific include file + ********/ + +#ifndef GPM2_DAEMON +#define GPM2_DAEMON + +/* parameters and options */ +#define GPM2_ARGS "c:f" +#define GPM2_CCONFIG "/etc/gpm2" + +struct gpm2_options { + char *cconfig; /* configuration directory */ +} opts; + +/* functions */ +int commandline(int argc, char **argv); +int mice_handler(); +int read_config(char *cconfig); +void set_defaults(); +void usage(); + + +/* structs */ + +struct mouse { + /* pointer to init and decode functions */ + int (*open)(int fd); +}; + +#endif diff --git a/src/gpm2/include/gpm2-data.h b/src/gpm2/include/gpm2-data.h new file mode 100644 index 0000000..64dafea --- /dev/null +++ b/src/gpm2/include/gpm2-data.h @@ -0,0 +1,59 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * data definitions used by clients and daemon + ********/ + +/* structs */ +struct gpm2_mouse { + char *name; + char *dev; + int fd; +}; + +struct gpm2_me { /* mouse element */ + struct gpm2_mouse mouse; + struct gpm2_me *next; + struct gpm2_me *prev; +}; + +struct gpm2_packet_raw() { /* raw mouse packets */ + char *data; + int len; +}; + +/* must contain everything a mouse can do */ +struct gpm2_packet() { /* decoded mouse packets */ + + int nr_buttons; + int *buttons; + + int pos_type; /* absolute or relativ */ +}; + +/* structure */ +struct gpm2_mic + +/* gpm2-daemon needs a list of mice, containing: + * - name of mouse + * - device used + * - filedescriptor + * - mouse configuration as found in cconfig + */ diff --git a/src/gpm2/include/gpm2-generic.h b/src/gpm2/include/gpm2-generic.h new file mode 100644 index 0000000..3081130 --- /dev/null +++ b/src/gpm2/include/gpm2-generic.h @@ -0,0 +1,25 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * generic functions: used by daemon and clients + ********/ + +/* generic functions */ +void mini_printf(char *str,int fd); diff --git a/src/gpm2/include/gpm2-io.h b/src/gpm2/include/gpm2-io.h new file mode 100644 index 0000000..8b7fc45 --- /dev/null +++ b/src/gpm2/include/gpm2-io.h @@ -0,0 +1,31 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * data definitions used by clients and daemon + ********/ + +#ifndef GPM2_IO_H +#define GPM2_IO_H + +char *read_packet(int fd, int len); /* needed? */ + + + +#endif diff --git a/src/gpm2/mice/README b/src/gpm2/mice/README new file mode 100644 index 0000000..d14013a --- /dev/null +++ b/src/gpm2/mice/README @@ -0,0 +1,63 @@ +This directory should contain the mice-protocol implementations. + +Each file (or if bigger: directory) implements one protocol. + +You have to create three functions: + + gpm2_open_(); + gpm2_handle_(); + gpm2_close_(); + +It's not yet clear, how to register protocols to gpm2. + +First idea of inclusion: + +- create deps/mouse- containging all dependencies +- conf/built-options/mice specifies which mice protocols to include +- a script generates include/gpm2-daemon-mice.h containg a struct-array + that looks like: + + struct mice_protos { + char *name; + int (*open)(); + int (*handle)(); + int (*open)(); + }; + +-------------------------------------------------------------------------------- +More design ideas for using mice: + + - The gpm2_handle function gets a pointer to a char array containing the + data packet. + - The gpm2_handle function returns what the packet means + - gpm2_daemon may then decide what todo with this information + +-------------------------------------------------------------------------------- +It would be nice to have a read_config_ that reads and verifies +the protocol specific options. + +For this, it would be nice to have a libcconfig() like this: + + struct cconfig_fd *cconfig_open(char *dir); + struct cconfig_tree *cconfig_read_tree(struct cconfig_fd *which); + + struct cconfig_element *cconfig_select_below(char *basepath, struct cconfig_fd *which, ...); + + The tree, cconfig_read_tree creates could consist of elements + of the following definition: + + struct cconfig_element { + char *path; + struct stat sbuf; + }; + +-------------------------------------------------------------------------------- +gpm2_open_*: + - needs fd + - needs options + +-------------------------------------------------------------------------------- +struct datapacket *gpm2_read_*(int fd) + - reads one packet + - returns it +-------------------------------------------------------------------------------- diff --git a/src/gpm2/mice/deps/ps2 b/src/gpm2/mice/deps/ps2 new file mode 100644 index 0000000..181c4e1 --- /dev/null +++ b/src/gpm2/mice/deps/ps2 @@ -0,0 +1 @@ +mice/ps2.o diff --git a/src/gpm2/mice/init_mice_handler.c b/src/gpm2/mice/init_mice_handler.c new file mode 100644 index 0000000..37f2cb6 --- /dev/null +++ b/src/gpm2/mice/init_mice_handler.c @@ -0,0 +1,39 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * handle mice + ********/ + +/* unclean headers */ +#include +#include +#include +#include /* close */ + + +#include "gpm2-daemon.h" +#include "tmp/protocols.h" + +int init_mice_handler() +{ + /* open connections: pipes */ + + return 1; +} diff --git a/src/gpm2/mice/mice_handler.c b/src/gpm2/mice/mice_handler.c new file mode 100644 index 0000000..4d39b44 --- /dev/null +++ b/src/gpm2/mice/mice_handler.c @@ -0,0 +1,65 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * handle mice + ********/ + +/* unclean headers */ +#include +#include +#include +#include /* close */ + + +#include "gpm2-daemon.h" +#include "tmp/protocols.h" + +int mice_handler() +{ + + /* init_mice_handler(); + * open connections to gpm2_daemon: + * - one for each mouse: + * * raw channel (unidirectional) + * * decoded channel (unidirectional) + * * control channel (bidirectional) + */ + init_mice_handler(); + + /* init_mice: + * + * - open mousedev + * - drop priviliges after that + */ + //init_mice(); + + + //handle_mice(); /* forks and maintains mice */ + + /* dirty hack */ + int ps2test = open("/dev/psaux",O_RDWR); + + gpm2_open_ps2(ps2test); + gpm2_decode_ps2(ps2test); + + close(ps2test); + + return 0; +} diff --git a/src/gpm2/mice/ps2.c b/src/gpm2/mice/ps2.c new file mode 100644 index 0000000..ff68abb --- /dev/null +++ b/src/gpm2/mice/ps2.c @@ -0,0 +1,121 @@ +/* + * gpm2 - mouse driver for the console + * + * Copyright (c) 2007 Nico Schottelius + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * + * handle standard ps2 + ********/ + +#include /* usleep() */ +#include /* tcflush() */ +#include + +#include "gpm2-daemon.h" +#include "gpm2-generic.h" + +/* protocol handler stolen from gpm1/mice.c */ + +/* ps2 protocol description + * + * 3 Bytes per packet + * + * first bit of data[0]: Left Button + * second bit of data[0]: Right Button + * third bit of data[0]: Middle Button + * fourth bit of data[0]: Always 1 + * fifth bit of data[0]: X Sign + * sixth bit of data[0]: Y Sign + * seventh bit of data[0]: X Overflow + * eighth bit of data[0]: Y Overflow + * + * data[1]: X Movement + * data[2]: Y Movement + */ + +/* standard ps2 */ +/* FIXME: implement error handling and options as described on + * http://www.computer-engineering.org/ps2mouse/ + */ +int gpm2_open_ps2(int fd) +{ + //static unsigned char s[] = { 246, 230, 244, 243, 100, 232, 3, }; +// write(fd, s, sizeof (s)); + +// static unsigned char s[] = { 246, 230, 244, 243, 100, 232, 3, }; + + char obuf, ibuf; + /* FIXME: check return */ + + obuf = 0xff; /* reset mouse */ + write(fd, &obuf, 1); + read(fd,&ibuf,1); + printf("RX: %#hhx\n",ibuf); +// if(ibuf != 0xfa) return 0; + +// obuf = 0xf6; /* set mouse to default */ +// write(fd, &obuf, 1); +// read(fd,&ibuf,1); +// printf("DF: %#hhx\n",ibuf); + + obuf = 0xf2; /* device id */ + write(fd, &obuf, 1); + read(fd,&ibuf,1); + printf("ST: %#hhx\n",ibuf); + read(fd,&ibuf,1); + printf("DI: %#hhx\n",ibuf); + + /* set resolution: 0xe8 */ + + //if(scaling = 2) { e7h + // + // 0xe6 scaling =1 + + /* do 0xf2, get device id and print it out */ + /* do 0xe9 and print out values as status */ + + /* FIXME: time correct? */ + usleep (30000); + tcflush (fd, TCIFLUSH); + return 0; + +} + +/* returs gpm2-readable data */ +//int *gpm2_decode_ps2(char *data, struct mousedata *decoded) +int gpm2_decode_ps2(int fd) +{ + char data[3]; + + data[0] = 0; + data[1] = 0; + data[2] = 0; + + read(fd,data,3); + + if(data[0] & 0x01) mini_printf("left!\n",1); + if(data[0] & 0x02) mini_printf("right!\n",1); + if(data[0] & 0x04) mini_printf("middle!\n",1); + + /* decoded->button_left = data[0] & 0x01; + decoded->button_right = data[0] & 0x02; + decoded->button_middle = data[0] & 0x04; + + decoded-> */ + + return 1; +} diff --git a/src/gpm2/scripts/generate_cbuiltconfig.sh b/src/gpm2/scripts/generate_cbuiltconfig.sh new file mode 100755 index 0000000..e182f80 --- /dev/null +++ b/src/gpm2/scripts/generate_cbuiltconfig.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Nico Schottelius +# 2007-05-11 +# First script to generate built environment from +# a standard cconfig directory for building. + +[ "$#" -eq 1 ] || exit 23 + +set -e + +# args +confdir="$1" + +# paths below the configuration directory +programs="programs" +progdir="$confdir/$programs" + +# paths directly in the srcdir +tmpdir="tmp" + +# +# generate built programs +# + +for tmp in "${progdir}"/*; do + prog="" + params="" + baseprog="$(basename "$tmp")" + destprog="$tmpdir/$baseprog" + + # ignore *.params, those are parameters, not programs + if [ "${tmp%.params}" != "${tmp}" ]; then + continue + fi + + # check for params + pfile="${tmp}.params" + if [ -f "$pfile" ]; then + params="$(head -n1 "$pfile")" + fi + + prog=$(head -n1 "$tmp") + + echo "Creating $destprog: $prog $params" + echo '#!/bin/sh' > "${destprog}" + echo "\"${prog}\" $params \"\$@\"" >> "${destprog}" + chmod 0700 "${destprog}" +done diff --git a/src/gpm2/scripts/include_protocols.sh b/src/gpm2/scripts/include_protocols.sh new file mode 100644 index 0000000..f731e9a --- /dev/null +++ b/src/gpm2/scripts/include_protocols.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Nico Schottelius +# 2007-05-13 +# Create protocol related files + +[ "$#" -eq 1 ] || exit 23 + +set -e + +# args +confdir="$1" + +# paths below the configuration directory +builtopts="built-options" +builtoptsdir="$confdir/$builtopts" + +# paths directly in the srcdir +tmpdir="tmp" + +# +# generate built programs +# + +: > "${tmpdir}/protocols.h" + +for proto in $(head -n1 ${builtoptsdir}/protocols); do + echo "int gpm2_open_${proto}(int fd);" > "${tmpdir}/protocols.h" + echo "int gpm2_decode_${proto}(int fd);" >> "${tmpdir}/protocols.h" +done diff --git a/src/gpm2/tmp/README b/src/gpm2/tmp/README new file mode 100644 index 0000000..30214bf --- /dev/null +++ b/src/gpm2/tmp/README @@ -0,0 +1 @@ +Directory for temporarily created files.