Damn Xan, you code like a BEAST O:)
This commit is contained in:
parent
4f4a898819
commit
7709abbc1c
5 changed files with 145 additions and 7 deletions
5
Makefile
Normal file
5
Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
all:
|
||||
$(MAKE) -C src all
|
||||
|
||||
clean:
|
||||
$(MAKE) -C src clean
|
95
configure
vendored
Executable file
95
configure
vendored
Executable file
|
@ -0,0 +1,95 @@
|
|||
#! /bin/sh
|
||||
|
||||
OS=`uname -s`
|
||||
PREFIX=/usr/local
|
||||
DEBUG=0
|
||||
|
||||
create_linux_config_h() {
|
||||
cat <<EOF > src/config.h
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include <endian.h>
|
||||
#define PATTY_INSTALL_PREFIX "$PREFIX"
|
||||
#endif /* _CONFIG_H */
|
||||
EOF
|
||||
}
|
||||
|
||||
create_darwin_config_h() {
|
||||
cat <<EOF > src/config.h
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include <architecture/byte_order.h>
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
#define __DO_SWAP_BYTES
|
||||
#endif /* _DO_SWAP_BYTES */
|
||||
#define PATTY_INSTALL_PREFIX "$PREFIX"
|
||||
#endif /* _CONFIG_H */
|
||||
EOF
|
||||
}
|
||||
|
||||
create_common_build_mk() {
|
||||
if [ "$DEBUG" = 1 ]; then
|
||||
cat <<EOF > mk/build.mk
|
||||
PREFIX = $PREFIX
|
||||
|
||||
CGFLAGS = -g -fno-inline
|
||||
EOF
|
||||
else
|
||||
cat <<EOF > mk/build.mk
|
||||
PREFIX = $PREFIX
|
||||
|
||||
CGFLAGS =
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
create_linux_build_mk() {
|
||||
create_common_build_mk $@
|
||||
|
||||
cat <<'EOF' >> mk/build.mk
|
||||
LLFLAGS = -shared -Wl,-soname=$(SONAME)
|
||||
|
||||
SONAME_SHORT = lib$(LIBNAME).so
|
||||
SONAME = $(SONAME_SHORT).$(VERSION_MAJOR)
|
||||
SONAME_FULL = $(SONAME_SHORT).$(VERSION)
|
||||
EOF
|
||||
}
|
||||
|
||||
create_darwin_build_mk() {
|
||||
create_common_build_mk $@
|
||||
|
||||
cat <<'EOF' >> mk/build.mk
|
||||
LLFLAGS = -dynamiclib -current_version $(VERSION)
|
||||
|
||||
STATIC = lib$(LIBNAME).a
|
||||
|
||||
SONAME_SHORT = $(LIBNAME).dylib
|
||||
SONAME = lib$(LIBNAME).$(VERSION_MAJOR).dylib
|
||||
SONAME_FULL = lib$(LIBNAME).$(VERSION).dylib
|
||||
EOF
|
||||
}
|
||||
|
||||
for arg in $@; do
|
||||
case $arg in
|
||||
"--enable-debug")
|
||||
DEBUG=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -d "mk" ]; then
|
||||
mkdir -m 0755 mk
|
||||
fi
|
||||
|
||||
case $OS in
|
||||
Linux)
|
||||
create_linux_config_h
|
||||
create_linux_build_mk
|
||||
;;
|
||||
|
||||
Darwin)
|
||||
create_darwin_config_h
|
||||
create_darwin_build_mk
|
||||
;;
|
||||
esac
|
|
@ -25,8 +25,8 @@ enum patty_kiss_command {
|
|||
PATTY_KISS_RETURN = 0xff
|
||||
};
|
||||
|
||||
int patty_kiss_read(int fd, void *buf, size_t *len, int *channel);
|
||||
ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port);
|
||||
|
||||
int patty_kiss_write(int fd, const void *buf, size_t len, int channel);
|
||||
ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port);
|
||||
|
||||
#endif /* _PATTY_KISS_H */
|
||||
|
|
29
src/Makefile
Normal file
29
src/Makefile
Normal file
|
@ -0,0 +1,29 @@
|
|||
include ../mk/build.mk
|
||||
|
||||
INCLUDE_PATH = ../include
|
||||
HEADER_SUBDIR = birch
|
||||
|
||||
CC = $(CROSS)cc
|
||||
CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH)
|
||||
LDFLAGS =
|
||||
|
||||
HEADERS = kiss.h ax25.h
|
||||
OBJS = kiss.o
|
||||
|
||||
PROGRAM =
|
||||
|
||||
AR = $(CROSS)ar
|
||||
RANLIB = $(CROSS)ranlib
|
||||
|
||||
RM = /bin/rm
|
||||
LN = /bin/ln
|
||||
RMDIR = /bin/rmdir
|
||||
INSTALL = /usr/bin/install
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
$(OBJS): %.o: %.c $(HEADERS_BUILD)
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
$(RM) -f $(OBJS)
|
19
src/kiss.c
19
src/kiss.c
|
@ -1,3 +1,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <patty/kiss.h>
|
||||
|
||||
enum kiss_flags {
|
||||
|
@ -19,7 +24,7 @@ ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port) {
|
|||
for (i=0; i<len; i++) {
|
||||
unsigned char c = ((char *)buf)[i];
|
||||
|
||||
if (flags & KISS_FRAME == 0) {
|
||||
if ((flags & KISS_FRAME) == 0) {
|
||||
if (c == PATTY_KISS_FEND) {
|
||||
flags |= KISS_FRAME;
|
||||
}
|
||||
|
@ -60,7 +65,7 @@ ssize_t patty_kiss_read(int fd, void *buf, size_t len, int *port) {
|
|||
* the high nybble to be the radio port number from which the
|
||||
* packet originated.
|
||||
*/
|
||||
if (c & 0x0f == 0) {
|
||||
if ((c & 0x0f) == 0) {
|
||||
*port = (c & 0xf0) >> 4;
|
||||
|
||||
continue;
|
||||
|
@ -94,13 +99,12 @@ ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port) {
|
|||
goto error_io;
|
||||
}
|
||||
|
||||
if (write_command(PATTY_KISS_DATA, port) < 0) {
|
||||
if (write_command(fd, PATTY_KISS_DATA, port) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
unsigned char c = ((unsigned char *)buf)[i];
|
||||
ssize_t res = 0;
|
||||
unsigned char *escape = NULL;
|
||||
|
||||
switch (c) {
|
||||
|
@ -114,7 +118,12 @@ ssize_t patty_kiss_write(int fd, const void *buf, size_t len, int port) {
|
|||
|
||||
default: {
|
||||
end = i;
|
||||
res = write(fd, &c, 1); break;
|
||||
|
||||
if (write(fd, &c, 1) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue