From 3066baca509ef9929e6f4b32570115d9ee28dda6 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 25 Jan 2020 21:57:45 +0000 Subject: [PATCH] Begin v0.6 refurb Simplify GNUmakefile Reorganise objects declarations in objects.mk and makefiles Switch to clang compiler Switch to gold linker Stop building deps file on "make clean" New option to GNUmakefile: SKIPDEPS=1 to skip building deps file Make build less verbose New option to GNUmakefile: VERBOSE=1 for all compiler output Drop obsolete -D__STDC_CONSTANT_MACROS Drop MVP code from GNUmakefile Declared C++ standard to be C++14 Enabled many compiler warnings Removed ticonfig.c Renamed PLATTFORM_RASPBERRY to PLATFORM_RASPBERRY --- GNUmakefile | 179 ++++-------- Makefile.nmake | 26 +- defines.h | 2 +- main.cc | 2 +- objects.mk | 76 ++++-- player.cc | 4 +- tcp.cc | 2 +- ticonfig.c | 728 ------------------------------------------------- 8 files changed, 119 insertions(+), 900 deletions(-) delete mode 100644 ticonfig.c diff --git a/GNUmakefile b/GNUmakefile index 40b1728..4bd8628 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,152 +1,77 @@ -# valid platforms are mvp, raspberry and crossraspberry +# Switches for this Makefile: + +# VERBOSE - set to 1 to show all commands +# SKIPDEPS - Skip regeneration of dependencies file + +include objects.mk + +# valid platforms are raspberry and crossraspberry vomp_platform=$(shell ./select-platform) -#vomp_platform=crossraspberry $(info selected $(vomp_platform)) -vomp_options= # uncomment the line below if you want to build vomp application without a reboot option, automatically set for windows! #vomp_options+= -DVOMP_HAS_EXIT - - -ifeq ($(vomp_platform),mvp) -$(info MVP crosscompiler) -include ../crosstool/cross-var -CC=$(CROSS)gcc -STRIP=$(CROSS)strip -CXX=$(CROSS)g++ -LD=$(CROSS)g++ +ifdef VERBOSE +Q = +else +Q = @ endif ifeq ($(vomp_platform),raspberry) -$(info raspberry normal compiler) -CC=gcc +$(info Raspberry Pi native compiler) +CC=clang-9 STRIP=strip -CXX=g++ -LD=g++ +CXX=clang++-9 +LD=clang++-9 vomp_options += -DIPV6 +LDFLAGS = -fuse-ld=gold $(PICTURES) +LIBPATHS = -L/opt/vc/lib -L/usr/lib/arm-linux-gnueabihf +LIBS = -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample +LIBS += -ldl -lfontconfig -lfreetype -lMagick++-6.Q16 +OBJECTS = $(OBJ_COMMON) $(OBJ_RASPBERRY) +CROSSLIBS = +INCLUDES = -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/usr/include/freetype2 -I/usr/include/ImageMagick -I/usr/include/ImageMagick-6 -I/usr/include/arm-linux-gnueabihf/ImageMagick-6 +PLATFORM = -DVOMP_PLATFORM_RASPBERRY +CXXFLAGS_EXTRA = endif ifeq ($(vomp_platform),crossraspberry) -$(info raspberry cross compiler) +$(info Raspberry Pi cross compiler) CC=arm-linux-gnueabi-gcc-4.7 STRIP=arm-linux-gnueabi-strip CXX=arm-linux-gnueabi-g++-4.7 LD=arm-linux-gnueabi-g++-4.7 -endif - - -CXXFLAGS_DEV = -g -O0 -Wall -Wshadow -Wno-psabi -DDEV -D_GNU_SOURCE $(INCLUDES) $(vomp_options) -CXXFLAGS_REL = -O3 -Wall -Wshadow -D_GNU_SOURCE $(INCLUDES) $(vomp_options) -LIBPATHS = - - -$(info Setting up objects) -# This is the only thing windows and linux share -include objects.mk -OBJECTSWIN = threadwin.o remotewin.o ledwin.o mtdwin.o videowin.o audiowin.o osdwin.o surfacewin.o -OBJECTS = $(OBJECTS1) - -# Pictures for linux builds -PICTURES = -Wl,--format=binary -PICTURES += -Wl,other/vdrhires.png -PICTURES += -Wl,other/wallpaper720p.jpg -PICTURES += -Wl,other/properties.png -PICTURES += -Wl,other/radio.png -PICTURES += -Wl,other/timers.png -PICTURES += -Wl,other/tv.png -PICTURES += -Wl,other/recordings.png -PICTURES += -Wl,other/restart.png -PICTURES += -Wl,other/hd1080i.png -PICTURES += -Wl,other/hd720p.png -PICTURES += -Wl,other/sd576i.png -PICTURES += -Wl,other/txtoff.png -PICTURES += -Wl,other/txton.png -PICTURES += -Wl,other/dolbyoff.png -PICTURES += -Wl,other/dolbyon.png -PICTURES += -Wl,other/recording.png -PICTURES += -Wl,other/recfolder.png -PICTURES += -Wl,other/defposter.png -PICTURES += -Wl,--format=default - - - - -ifeq ($(vomp_platform),mvp) -$(info MVP flags) -LDFLAGS = -Wall -static -LIBS = -lpthread -lrt - -OBJECTS += wwss.o main.o threadp.o remotemvp.o ledmvp.o mtdmvp.o videomvp.o audiomvp.o osdmvp.o \ - surfacemvp.o fonts/helvB24.o fonts/helvB18.o wjpegcomplex.o vmedialist.o vcolourtuner.o \ - audioplayer.o demuxeraudio.o \ - vmediaview.o vvideomedia.o imagereader.o media.o mediaoptions.o mediaplayer.o serialize.o \ - localmediafile.o playermedia.o demuxermedia.o mediafile.o osdvector.o surfacevector.o -TIOBJECT = ticonfig.o -CROSSLIBS = ../jpeg/jpeg-6b/libjpeg.a -INCLUDES = -I../jpeg/jpeg-6b -DVOMP_PLATTFORM_MVP -endif - - -ifeq ($(vomp_platform),raspberry) -$(info Raspberry pi flags) -LDFLAGS = -Wall $(PICTURES) -LIBS = -L/opt/vc/lib -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample - -OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o imageomx.o wjpegsimple.o remotelinux.o signal.o -LIBS+= -ldl -lfontconfig -lfreetype -L/usr/lib/arm-linux-gnueabihf -lMagick++-6.Q16 -CROSSLIBS = -INCLUDES = -DVOMP_PLATTFORM_RASPBERRY -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/usr/include/freetype2 -I/usr/include/ImageMagick -I/usr/include/ImageMagick-6 -I/usr/include/arm-linux-gnueabihf/ImageMagick-6 -CXXFLAGS_DEV += -D__STDC_CONSTANT_MACROS -CXXFLAGS_REL += -D__STDC_CONSTANT_MACROS -endif - - -ifeq ($(vomp_platform),crossraspberry) -$(info Raspberry pi flags cross compiler) -LDFLAGS = -Wall $(PICTURES) -Wl,--verbose -Xlinker --rpath-link=rpi-root/usr/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/opt/vc/lib -LIBS = -Lrpi-root/opt/vc/lib -Lrpi-root/lib -Lrpi-root/usr/lib -Lrpi-root/lib/arm-linux-gnueabihf -Lrpi-root/usr/lib/arm-linux-gnueabihf -Lrpi-root/usr/local/lib -lpthread -lrt -lEGL -lOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample -ldl -lfontconfig - -OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o imageomx.o wjpegsimple.o remotelinux.o signal.o -LIBS+= -lfreetype -lMagick++-6.Q16 +LDFLAGS = $(PICTURES) -Wl,--verbose -Xlinker --rpath-link=rpi-root/usr/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/opt/vc/lib +LIBPATHS = -Lrpi-root/opt/vc/lib -Lrpi-root/lib -Lrpi-root/usr/lib -Lrpi-root/lib/arm-linux-gnueabihf -Lrpi-root/usr/lib/arm-linux-gnueabihf -Lrpi-root/usr/local/lib +LIBS = -lpthread -lrt -lEGL -lOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample -ldl -lfontconfig +LIBS += -lfreetype -lMagick++-6.Q16 +OBJECTS = $(OBJ_COMMON) $(OBJ_RASPBERRY) CROSSLIBS = -INCLUDES = -DVOMP_PLATTFORM_RASPBERRY -Irpi-root/opt/vc/include -Irpi-root/opt/vc/include/interface/vcos/pthreads -Irpi-root/usr/include -Irpi-root/usr/include/freetype2 -Irpi-root/usr/include/ImageMagick-6 -Irpi-root/usr/include/ImageMagick -Irpi-root/usr/include/arm-linux-gnueabihf/ImageMagick-6 -CXXFLAGS_DEV += -D__STDC_CONSTANT_MACROS -mfloat-abi=hard -CXXFLAGS_REL += -D__STDC_CONSTANT_MACROS -mfloat-abi=hard +INCLUDES = -Irpi-root/opt/vc/include -Irpi-root/opt/vc/include/interface/vcos/pthreads -Irpi-root/usr/include -Irpi-root/usr/include/freetype2 -Irpi-root/usr/include/ImageMagick-6 -Irpi-root/usr/include/ImageMagick -Irpi-root/usr/include/arm-linux-gnueabihf/ImageMagick-6 +PLATFORM = -DVOMP_PLATFORM_RASPBERRY +CXXFLAGS_EXTRA = -mfloat-abi=hard endif +CXXFLAGS_DEV = -g -O0 -Wall -Wextra -Wshadow -Werror=return-type -Wmissing-declarations -Winit-self -Woverloaded-virtual -Wold-style-cast -Wconversion -std=c++14 $(CXXFLAGS_EXTRA) -DDEV -D_GNU_SOURCE $(PLATFORM) $(vomp_options) $(INCLUDES) +CXXFLAGS_REL = -O3 -Wall -Werror -std=c++14 $(CXXFLAGS_EXTRA) -D_GNU_SOURCE $(PLATFORM) $(vomp_options) $(INCLUDES) + .PHONY: clean fresh all install strip default: dev fresh: clean default -vompclient: $(OBJECTS) $(TIOBJECT) $(CROSSLIBS) - $(LD) $(LDFLAGS) $(LIBPATHS) $(RELEASE) $(vomp_options) -o vompclient $(TIOBJECT) $(OBJECTS) $(CROSSLIBS) $(LIBS) +%.o: %.cc + @echo CC $@ + $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< -# A slight hash up -ticonfig.o: - $(CC) $(CXXFLAGS_REL) -c -o ticonfig.o ticonfig.c +vompclient: $(OBJECTS) $(CROSSLIBS) + @echo LD vompclient + $(Q)$(LD) $(LDFLAGS) $(LIBPATHS) -o vompclient $(OBJECTS) $(CROSSLIBS) $(LIBS) strip: - $(STRIP) vompclient - -install: - rm -f target-mvp/vompclient - cp vompclient target-mvp/vompclient - -install-wmp: - rm -f target-wmvp/vompclient - cp vompclient target-wmvp/vompclient - -install-dev: - rm -f target-mvp-dev/vompclient - cp vompclient target-mvp-dev/vompclient - -debug: - ../../gdb/gdb-7.12.1/gdb/gdb target-mvp/vompclient target-mvp/core.* - -debug2: - ../../gdb/gdb-7.12.1/gdb/gdb target-mvp-dev/vompclient target-mvp-dev/core.* + @echo STRIP vompclient + $(Q)$(STRIP) vompclient dev: CXXFLAGS := $(CXXFLAGS_DEV) dev: vompclient @@ -154,11 +79,15 @@ dev: vompclient release: CXXFLAGS := $(CXXFLAGS_REL) release: clean vompclient strip -deps: GNUmakefile - $(CC) -MM $(INCLUDES) $(OBJECTS:%.o=%.cc) > deps - --include deps - clean: rm -f *.o deps vompclient *~ fonts/*.o fonts/*~ teletxt/*.o +ifndef SKIPDEPS +deps: GNUmakefile + @echo "DEPS" + $(Q)$(CC) -MM $(INCLUDES) $(OBJECTS:%.o=%.cc) > deps +endif + +ifneq ($(MAKECMDGOALS),clean) +include deps +endif diff --git a/Makefile.nmake b/Makefile.nmake index 4573765..2429484 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -1,14 +1,6 @@ - -############################### - -# ! Chris - WRONG FILE ! - -############################### - - CXXFLAGS_DEV = -g -O0 -Wall -Woverloaded-virtual -Wshadow -Werror -DDEV -D_GNU_SOURCE $(INCLUDES) -CXXFLAGS_REL = /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "NEW_DEMUXER" /nologo /EHsc /MD /GS /W3 /c /TP -LDFLAGS = /INCREMENTAL:NO /NOLOGO /NODEFAULTLIB /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LIBPATH:"$(DXSDK_DIR)\Lib\x86" +CXXFLAGS_REL = /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "NEW_DEMUXER" /nologo /EHsc /MD /GS /W3 /c /TP +LDFLAGS = /INCREMENTAL:NO /NOLOGO /NODEFAULTLIB /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LIBPATH:"$(DXSDK_DIR)\Lib\x86" LIBS = Msvcrt.lib Ws2_32.lib shlwapi.lib d3d9.lib Iphlpapi.lib Strmiids.lib Mfuuid.lib winmm.lib MSVCPRT.lib kernel32.lib user32.lib gdi32.lib ole32.lib uuid.lib oleaut32.lib @@ -20,17 +12,7 @@ CROSSLIBS = !include "objects.mk" - -OBJECTSWIN = winmain.o threadwin.o remotewin.o ledwin.o mtdwin.o videowin.o audiowin.o windowsosd.o dsallocator.o dssourcefilter.o dssourcepin.o wwinvideofilter.o wwinvideoh264filter.o wwinaudiofilter.o wwinmp3audiofilter.o wjpegsimple.o - - -OBJECTSWINLEGACY = osdvector.o surfacevector.o osdwinpixel.o surfacewin.o fonts/helvB24.o fonts/helvB18.o - -OBJECTSWINCURRENT = osdvector.o surfacevector.o osdwinvector.o - - - -OBJECTS = $(OBJECTS1) $(OBJECTSWIN) +OBJECTS = $(OBJ_COMMON) $(OBJ_WINDOWS) #.PHONY: clean fresh all install strip @@ -39,7 +21,7 @@ default: release #dev !ifdef LEGACY release:: CXXFLAGS= /D "WINDOWS_LEGACY" $(CXXFLAGS_REL) -OBJECTS = $(OBJECTS) $(OBJECTSWINLEGACY) +OBJECTS = $(OBJECTS) $(OBJ_WINLEGACY) LIBS = $(LIBS) $(LIBSLEGACY) release:: vompclient-legacy.exe diff --git a/defines.h b/defines.h index 18048a4..6dfc56b 100644 --- a/defines.h +++ b/defines.h @@ -107,7 +107,7 @@ int getClockRealTime(struct timespec *tp); #define CLOSESOCKET close // add here defines for plattform specific objects -#ifdef VOMP_PLATTFORM_RASPBERRY +#ifdef VOMP_PLATFORM_RASPBERRY #define Remote_TYPE RemoteLinux // Generic Remote under Linux (Konsole!, not X) will support in the end: #define RemoteStartDev ""//No devices passed diff --git a/main.cc b/main.cc index 0e9c3e1..8bf2536 100644 --- a/main.cc +++ b/main.cc @@ -69,7 +69,7 @@ extern "C" #endif -#ifdef VOMP_PLATTFORM_RASPBERRY +#ifdef VOMP_PLATFORM_RASPBERRY #include "mtdraspberry.h" #include "remotelinux.h" diff --git a/objects.mk b/objects.mk index 77dc1d7..fb45467 100644 --- a/objects.mk +++ b/objects.mk @@ -1,20 +1,56 @@ -OBJECTS1 = command.o tcp.o dsock.o thread.o timers.o i18n.o vdp6.o \ - message.o messagequeue.o udp.o wol.o audio.o video.o log.o mutex.o \ - vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o \ - directory.o mark.o option.o player.o playerradio.o vfeed.o afeed.o \ - demuxer.o demuxervdr.o demuxerts.o stream.o \ - region.o colour.o boxstack.o boxx.o tbboxx.o vrecording.o \ - vinfo.o vquestion.o vrecordinglist.o vrecordinglistclassic.o \ - vrecordinglistadvanced.o vepgsummary.o vepglistadvanced.o \ - vmute.o vvolume.o vtimerlist.o vtimeredit.o vrecordingmenu.o \ - vchannellist.o vwelcome.o vvideorec.o vepgsettimer.o \ - vchannelselect.o vserverselect.o vconnect.o vepg.o vrecmove.o \ - vradiorec.o vaudioselector.o vscreensaver.o vopts.o \ - wselectlist.o wjpeg.o wsymbol.o wbutton.o wtextbox.o \ - woptionpane.o woptionbox.o wremoteconfig.o wtabbar.o led.o \ - remote.o mtd.o osd.o surface.o vpicturebanner.o abstractoption.o \ - eventdispatcher.o vdrrequestpacket.o vdrresponsepacket.o \ - vvideolivetv.o vsleeptimer.o playerlivetv.o playerliveradio.o \ - wprogressbar.o bitmap.o dvbsubtitles.o tfeed.o vteletextview.o \ - teletextdecodervbiebu.o teletxt/txtfont.o movieinfo.o seriesinfo.o \ - wmovieview.o wseriesview.o tvmedia.o wtvmedia.o wpictureview.o +OBJ_COMMON = command.o tcp.o dsock.o thread.o timers.o i18n.o vdp6.o \ + message.o messagequeue.o udp.o wol.o audio.o video.o log.o mutex.o \ + vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o \ + directory.o mark.o option.o player.o playerradio.o vfeed.o afeed.o \ + demuxer.o demuxervdr.o demuxerts.o stream.o \ + region.o colour.o boxstack.o boxx.o tbboxx.o vrecording.o \ + vinfo.o vquestion.o vrecordinglist.o vrecordinglistclassic.o \ + vrecordinglistadvanced.o vepgsummary.o vepglistadvanced.o \ + vmute.o vvolume.o vtimerlist.o vtimeredit.o vrecordingmenu.o \ + vchannellist.o vwelcome.o vvideorec.o vepgsettimer.o \ + vchannelselect.o vserverselect.o vconnect.o vepg.o vrecmove.o \ + vradiorec.o vaudioselector.o vscreensaver.o vopts.o \ + wselectlist.o wjpeg.o wsymbol.o wbutton.o wtextbox.o \ + woptionpane.o woptionbox.o wremoteconfig.o wtabbar.o led.o \ + remote.o mtd.o osd.o surface.o vpicturebanner.o abstractoption.o \ + eventdispatcher.o vdrrequestpacket.o vdrresponsepacket.o \ + vvideolivetv.o vsleeptimer.o playerlivetv.o playerliveradio.o \ + wprogressbar.o bitmap.o dvbsubtitles.o tfeed.o vteletextview.o \ + teletextdecodervbiebu.o teletxt/txtfont.o movieinfo.o seriesinfo.o \ + wmovieview.o wseriesview.o tvmedia.o wtvmedia.o wpictureview.o + +OBJ_RASPBERRY = main.o threadp.o osdvector.o surfacevector.o osdopenvg.o \ + ledraspberry.o mtdraspberry.o videoomx.o audioomx.o imageomx.o \ + wjpegsimple.o remotelinux.o signal.o + +OBJ_WINDOWS = winmain.o threadwin.o remotewin.o ledwin.o mtdwin.o videowin.o \ + audiowin.o windowsosd.o dsallocator.o dssourcefilter.o dssourcepin.o \ + wwinvideofilter.o wwinvideoh264filter.o wwinaudiofilter.o \ + wwinmp3audiofilter.o wjpegsimple.o + +OBJ_WINLEGACY = osdvector.o surfacevector.o osdwinpixel.o surfacewin.o \ + fonts/helvB24.o fonts/helvB18.o + +OBJ_WINCURRENT = osdvector.o surfacevector.o osdwinvector.o + +# Pictures for linux builds +PICTURES = -Wl,--format=binary +PICTURES += -Wl,other/vdrhires.png +PICTURES += -Wl,other/wallpaper720p.jpg +PICTURES += -Wl,other/properties.png +PICTURES += -Wl,other/radio.png +PICTURES += -Wl,other/timers.png +PICTURES += -Wl,other/tv.png +PICTURES += -Wl,other/recordings.png +PICTURES += -Wl,other/restart.png +PICTURES += -Wl,other/hd1080i.png +PICTURES += -Wl,other/hd720p.png +PICTURES += -Wl,other/sd576i.png +PICTURES += -Wl,other/txtoff.png +PICTURES += -Wl,other/txton.png +PICTURES += -Wl,other/dolbyoff.png +PICTURES += -Wl,other/dolbyon.png +PICTURES += -Wl,other/recording.png +PICTURES += -Wl,other/recfolder.png +PICTURES += -Wl,other/defposter.png +PICTURES += -Wl,--format=default diff --git a/player.cc b/player.cc index f796190..f0fc4eb 100644 --- a/player.cc +++ b/player.cc @@ -478,7 +478,7 @@ void Player::switchState(UCHAR toState, ULONG jumpFrame) } case S_PAUSE_P: // to S_PAUSE_P { - #ifdef VOMP_PLATTFORM_RASPBERRY + #ifdef VOMP_PLATFORM_RASPBERRY vfeed.stop(); // can't vfeed during pause #endif @@ -567,7 +567,7 @@ void Player::switchState(UCHAR toState, ULONG jumpFrame) video->unPause(); audio->unPause(); - #ifdef VOMP_PLATTFORM_RASPBERRY + #ifdef VOMP_PLATFORM_RASPBERRY vfeed.start(false); #endif diff --git a/tcp.cc b/tcp.cc index 5aff9cf..278816c 100644 --- a/tcp.cc +++ b/tcp.cc @@ -115,7 +115,7 @@ void TCP::getMAC(char* dest) int TCP::connectTo(char* host, unsigned short port) { -#ifdef VOMP_PLATTFORM_RASPBERRY +#ifdef VOMP_PLATFORM_RASPBERRY #define IPV 6 #else #define IPV 4 diff --git a/ticonfig.c b/ticonfig.c deleted file mode 100644 index 18c82b3..0000000 --- a/ticonfig.c +++ /dev/null @@ -1,728 +0,0 @@ -// Adapted for vomp by Chris Tallon by changing "int main" to "int ticonfig_main" - -/* - * Copyright (C) 2006, Jon Gettler - * http://www.mvpmc.org/ - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEVNAME "eth1" - -typedef struct { - unsigned char device[16]; - unsigned long arg2; - unsigned long arg3; - unsigned long arg4; - void *ptr; -} ti_dev_t; - -typedef struct { - unsigned int len; - char name[128]; -} ti_name_t; - -typedef struct { - unsigned int unknown[3]; - unsigned int len; - char name[36]; - unsigned int unknown2[27]; -} ti_ssid_t; - -typedef struct { - unsigned int count; - ti_ssid_t ssid[32]; -} ti_ssid_list_t; - -static int sockfd = -1; -static int config_started = 0; -static char default_ssid[128]; -static char default_wep[128]; -static ti_ssid_list_t slist; -static int verbose = 0; - -static struct option opts[] = { - { "help", no_argument, 0, 'h' }, - { "probe", no_argument, 0, 'p' }, - { "ssid", required_argument, 0, 's' }, - { "verbose", no_argument, 0, 'v' }, - { "wep", required_argument, 0, 'w' }, - { 0, 0, 0, 0 } -}; - -static void -print_help(char *prog) -{ - printf("Usage: %s \n", prog); - printf("\t-h \tprint this help\n"); - printf("\t-p \tprobe for wireless networks\n"); - printf("\t-s ssid \tSSID to use\n"); - printf("\t-v \tverbose\n"); -} - -static int -read_vpd(void) -{ - int fd, i = 0; - short *mtd; - char *vpd, *network, *wep; - char path[64]; - - if ((fd=open("/proc/mtd", O_RDONLY)) > 0) { - FILE *f = fdopen(fd, "r"); - char line[64]; - /* read the header */ - fgets(line, sizeof(line), f); - /* read each mtd entry */ - while (fgets(line, sizeof(line), f) != NULL) { - if (strstr(line, " VPD") != NULL) { - break; - } - i++; - } - fclose(f); - close(fd); - } - - if (i != 2) { - fprintf(stderr, "not running on a wireless MVP!\n"); - return -1; - } - - snprintf(path, sizeof(path), "/dev/mtd%d", i); - - if ((fd=open(path, O_RDONLY)) < 0) - return -1; - - if ((mtd=malloc(65536)) == NULL) { - close(fd); - return -1; - } - - if (read(fd, mtd, 65536) != 65536) { - close(fd); - return -1; - } - - vpd = (char*)mtd; - - close(fd); - - network = vpd+0x2008; - wep = vpd+0x2035; - - if (network[0] != '\0') { - if (verbose) - printf("Default wireless network: '%s'\n", network); - strcpy(default_ssid, network); - } else { - if (verbose) - printf("No default wireless network found in flash\n"); - } - - if (wep[0] != '\0') { - if (verbose) - printf("WEP key found!\n"); - strcpy(default_wep, wep); - } else { - if (verbose) - printf("WEP key not found!\n"); - } - - if (vpd[0x3000] != '\0') { - if (verbose) - printf("Default server: %d.%d.%d.%d\n", - vpd[0x3000], vpd[0x3001], - vpd[0x3002], vpd[0x3003]); - } else { - if (verbose) - printf("No default server found in flash\n"); - } - - free(mtd); - - return 0; -} -static int -init_device(int fd, char *name) -{ - ti_dev_t dev; - ti_name_t ssid; - - memset(&dev, 0, sizeof(dev)); - memset(&ssid, 0, sizeof(ssid)); - - strcpy(dev.device, name); - dev.arg2 = 0x00223834; - dev.arg3 = 0x2; - dev.arg4 = 0xd; - dev.ptr = &ssid; - - if (ioctl(fd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - if (verbose) - printf("device initialized!\n"); - - return 0; -} - -static int -start_config_manager(int fd, char *name) -{ - ti_dev_t dev; - unsigned long buf[256]; - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, name); - dev.arg2 = 0x0022381c; - dev.arg3 = 0x2; - dev.arg4 = 0x4; - dev.ptr = (void*)0x1; - - if (ioctl(fd, SIOCDEVPRIVATE, &dev) != 0) { - if (errno == EALREADY) { - if (verbose) - printf("config manager already running!\n"); - return 0; - } - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - if (verbose) - printf("config manager started!\n"); - - config_started = 1; - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223818; - dev.arg3 = 0x1; - dev.arg4 = 0x4; - dev.ptr = (void*)0x0; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222018; - dev.arg3 = 0x2; - dev.arg4 = 0x24; - dev.ptr = (void*)buf; - - buf[0] = 0x00000008; - memcpy(buf+1, "NON-SSID", 8); - buf[3] = 0x00000000; - buf[4] = 0x00000000; - buf[5] = 0x00000000; - buf[6] = 0x00000000; - buf[7] = 0x00000000; - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - return 0; -} - -static int -up_device(int fd, char *name) -{ - ti_dev_t dev; - unsigned long buf[256]; - - if (verbose) - printf("Bringing up eth1...\n"); - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00224420; - dev.arg3 = 0x1; - dev.arg4 = 0x75; - dev.ptr = (void*)buf; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222018; - dev.arg3 = 0x2; - dev.arg4 = 0x24; - dev.ptr = (void*)buf; - - buf[0] = strlen(default_ssid); - strcpy((char*)(&buf[1]), default_ssid); - - if (verbose) - printf("Using SSID: '%s'\n", default_ssid); - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00224420; - dev.arg3 = 0x1; - dev.arg4 = 0x75; - dev.ptr = (void*)buf; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223028; - dev.arg3 = 0x1; - dev.arg4 = 0x4; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - -#if 0 - if (verbose) { - printf("Signal strength: %ddb\n", (int)dev.ptr); - printf("Signal strength: %p\n", dev.ptr); - } -#endif - - return 0; -} - -static void -wep_copy(char *buf, char *key) -{ - int i, len; - - len = strlen(key) / 2; - - for (i=0; i='0') && (h<='9')) { - h = h - '0'; - } else { - h = h - 'A' + 10; - } - if ((l>='0') && (l<='9')) { - l = l - '0'; - } else { - l = l - 'A' + 10; - } - - buf[i] = (h << 4) | l; - } -} - -static int -up_device_wep(int fd, char *name) -{ - ti_dev_t dev; - unsigned long buf[256]; - - if (verbose) - printf("Bringing up WEP-enabled eth1...\n"); - - if (init_device(sockfd, DEVNAME) < 0) - return -1; - - if (start_config_manager(sockfd, DEVNAME) < 0) - return -1; - -#if 0 - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00224420; - dev.arg3 = 0x1; - dev.arg4 = 0x75; - dev.ptr = (void*)buf; - strcpy((char*)buf, default_ssid); - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222018; - dev.arg3 = 0x2; - dev.arg4 = 0x24; - dev.ptr = (void*)buf; - - buf[0] = strlen(default_ssid); - strcpy((char*)(&buf[1]), default_ssid); - - if (verbose) - printf("Using SSID: '%s'\n", default_ssid); - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } -#endif - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223410; - dev.arg3 = 0x2; - dev.arg4 = 0x4; - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223488; - dev.arg3 = 0x2; - dev.arg4 = 0x4; - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - /* - * XXX: this error seems normal - */ -#if 0 - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; -#endif - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223404; - dev.arg3 = 0x2; - dev.arg4 = 0x2c; - dev.ptr = (void*)buf; - - buf[0] = 0x2c; - buf[1] = 0x80000000; - buf[2] = 0xd; - wep_copy((char*)(buf+3), default_wep); - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222018; - dev.arg3 = 0x2; - dev.arg4 = 0x24; - dev.ptr = (void*)buf; - - buf[0] = strlen(default_ssid); - strcpy((char*)(&buf[1]), default_ssid); - - if (verbose) - printf("Using SSID: '%s'\n", default_ssid); - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00224420; - dev.arg3 = 0x1; - dev.arg4 = 0x75; - dev.ptr = (void*)buf; - strcpy((char*)(&buf[0]), default_ssid); - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&buf, 0, sizeof(buf)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00224420; - dev.arg3 = 0x1; - dev.arg4 = 0x75; - dev.ptr = (void*)buf; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } - -#if 0 - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00223028; - dev.arg3 = 0x1; - dev.arg4 = 0x4; - - if (ioctl(sockfd, SIOCDEVPRIVATE+1, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE+1)"); - return -1; - } -#endif - - return 0; -} - -int -get_ssid_list(int fd, char *name) -{ - ti_dev_t dev; - int n; - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, name); - dev.arg2 = 0x00222c20; - - if (ioctl(fd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, name); - dev.arg2 = 0x00222c1c; - dev.arg3 = 0x1; - dev.arg4 = 0x4; - - if (ioctl(fd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - memset(&slist, 0, sizeof(slist)); - strcpy(dev.device, name); - dev.arg2 = 0x0022200c; - dev.arg3 = 0x1; - dev.arg4 = 0x2710; - dev.ptr = (void*)&slist; - - if (ioctl(fd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - n = slist.count; - - if ((n > 0) && verbose) - printf("Found %d wireless networks!\n", n); - - return n; -} - -static int -init(void) -{ - struct ifreq ifr; - ti_dev_t dev; - - strncpy(ifr.ifr_name, DEVNAME, IFNAMSIZ); - - if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - perror("socket()"); - return -1; - } - - if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { - perror("ioctl(SIOCGIFFLAGS)"); - return -1; - } - - if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) { - perror("ioctl(SIOCSIFFLAGS)"); - return -1; - } - - if (init_device(sockfd, DEVNAME) < 0) - return -1; - - if (start_config_manager(sockfd, DEVNAME) < 0) - return -1; - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222020; - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - memset(&dev, 0, sizeof(dev)); - strcpy(dev.device, DEVNAME); - dev.arg2 = 0x00222c20; - - if (ioctl(sockfd, SIOCDEVPRIVATE, &dev) != 0) { - perror("ioctl(SIOCDEVPRIVATE)"); - return -1; - } - - return 0; -} - -int -ticonfig_main(int argc, char **argv) -{ - int c, n, i; - int opt_index; - int do_probe = 0; - char *ssid = NULL, *key = NULL; - int found = 0; - int with_wep = -1; - - while ((c=getopt_long(argc, argv, - "hps:w:v", opts, &opt_index)) != -1) { - switch (c) { - case 'h': - print_help(argv[0]); - exit(0); - break; - case 'p': - do_probe = 1; - break; - case 's': - ssid = strdup(optarg); - break; - case 'w': - if (strcasecmp(optarg, "off") == 0) { - with_wep = 0; - } else if (strcasecmp(optarg, "on") == 0) { - with_wep = 1; - } else { - with_wep = 1; - key = strdup(optarg); - } - break; - case 'v': - verbose = 1; - break; - default: - print_help(argv[0]); - exit(1); - break; - } - } - - if (read_vpd() != 0) { - fprintf(stderr, "VPD read failed!\n"); - exit(1); - } - if (key) - strcpy(default_wep, key); - - if (init() != 0) { - fprintf(stderr, "initialization failed!\n"); - exit(1); - } - - n = get_ssid_list(sockfd, DEVNAME); - - /* - * After starting the config manager, we may need to wait a bit... - */ - if ((n == 0) && (config_started == 1)) { - sleep(1); - n = get_ssid_list(sockfd, DEVNAME); - } - - if (n < 0) { - fprintf(stderr, "SSID probe failed!\n"); - exit(1); - } else if (n == 0) { - fprintf(stderr, "no wireless networks found!\n"); - exit(1); - } - - if (do_probe) { - for (i=0; i