Raspi 3 + Huawei 3531 = SMS server

16. Juli 2016 um 14:29 | Veröffentlicht in Hardware, Software | 3 Kommentare
Schlagwörter: , , , , , , ,

Pooh, quite some work to do, but now it seems to work…

The problem was simple: I have a Raspi 3, and a Huawei 3531 3G USB stick. The Raspi shall work as monitoring server running icinga2, and for emergency cases, it shall send SMS using the USB stick.

It turned out that this is highly complicated stuff, and that it is very difficult to find a solution. So I decided to get my „it’s running somehow solution“ published here. As I’m actually not a system administrator, although I got a bit of knowledge during the past 30 years, it is not clear to me yet, why the intended solution (with usb_modeswitch alone) does not work. However, this solution does work, and that’s what’s important to me 😉

What do we need?

  • Raspian Jessie
  • usb_modeswitch
  • cron
  • a Huawei 3531 USB Surf Stick

(I did not succeed to get things up and running with usb_modeswitch only!)

Be sure that there is NO pin set for the stick (plug it first on a Mac or Win machine and change that setting through the web interface of the stick)!

This solution should work if you get the following result when entering lsusb after you have plugged in the stick:

Bus 001 Device 004: ID 12d1:1f01 Huawei Technologies Co., Ltd.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

This tells us that the stick is in the default mode, which means that you have a wlan0interface in the list when you perform ifconfig.

To get access as SMS modem, we have to switch the stick into a different mode. This requires some magic. So, if you do not get exactly the same outputs, and do not have exactly that type of stick, it is highly probable that you won’t succeed.

The step-by-step solution:

  1. Create a shell script under /usr/local/sbin/huawei.sh. Do not forget to make it executable with chmod +x /usr/local/sbin/huawei.sh! You probably have to call the editor with sudo (e.g., sudo vi /usr/local/sbin/huawei.sh)
  2. Fill this code into that shell script:
    RESULT=`lsusb | grep -q 12d1:1001 && echo $?`
    echo "result: $RESULT"

    if [ "$RESULT" = "" ]
    then
    echo "Switching Huawei 3531 to modem mode..."
       sudo /usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'
    fi

    if [ "$RESULT" = "0" ]
    then
       echo "Huawei 3531 already switched to modem mode."
    fi

    if [ "RESULT" = "1" ]
    then
       echo "Switching Huawei 3531 to modem mode..."
       sudo /usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'
    fi

    This is the cron-script we will periodically execute, and that performs the switch to the modem mode of the stick.

  3. Call the crontab editor with sudo crontab -e.

  4. Add this line to the crontab and save it:
    * * * * * /usr/local/sbin/huawei.sh

    This checks every minute if the stick is in the right mode. If not, it switches the stick by calling the above script.

  5. Install usb_modeswitch:
    sudo apt-get install usb-modeswitch
  6. Ensure that the settings in /etc/usb_modeswitch.confare set this way:
    #DisableSwitching=0
    EnableLogging=1
    #SetStorageDelay=4

  7. In /etc/usb_modeswitch.dcreate a file name 12d1:1f01.
  8. Put this into that file:
    # Huawei E3531
    TargetVendor=0x12d1

    TargetProduct=0x1001
    MessageContent="55534243123456780000000000000011062000000100000000000000000000"
    NoDriverLoading=1

    Actually, this should be sufficient to make the stick switch, but it wasn’t. That’s the reason why we use the cronjob.

When entering lsusbafter a reboot, latest after a minute this should be the result:

Bus 001 Device 005: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now, you can install gammu from  http://de.wammu.eu/smsd/ and configure it (see below). This is a SMS server daemon, which you can use to send messages pretty easily:

echo "test" | sudo gammu-smsd-inject TEXT "+49<your mobile number>"

After a few seconds, you should receive the SMS on your mobile device.

The configuration is quite easy to perform, just edit /etc/gammu-smsdrc and set these values (the pin entry is required even if the stick has none active):

# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)

[gammu]
# Please configure this!
port = /dev/ttyUSB0
connection = at

# Debugging
logformat = textalldate

# SMSD configuration, see gammu-smsdrc(5)
[smsd]
pin = 0000
service = files
# logfile = syslog
logfile = /var/log/gammu-smsd
# Increase for debugging information
debuglevel = 4
ReceiveFrequency = 60
# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/

MacMini as Nagios server

7. März 2013 um 20:29 | Veröffentlicht in Hardware, Software | Hinterlasse einen Kommentar
Schlagwörter: , , , ,

To keep control of my farm, I wanted to set up my MacMini as Nagios server. I tried around a bit, first with a MacPorts-based solution I found in the web. However, I did not succeed in integrating Nagios into my OSX Server’s Apache, although Nagios itself did work.

By change, I found a really excellent tool, which runs on OSX Server 10.8, and requires nearly no more actions from the Admin: https://github.com/ygini/easyNagiosForOSXServer.

You just start it, wait, perform two actions in the Server.App, and that’s it… really great!

vSphere on MacMini – Part 2

6. März 2013 um 12:43 | Veröffentlicht in Hardware, Software | Hinterlasse einen Kommentar
Schlagwörter: , , ,

Well, after running the vSphere Hypervisor on my MacMini for some time, I returned to OSX.

Why?

Well, although the machine went fine, there were some problems that turned out during operation:

  1. The management was only possible through the Windows client. There is a Web admin interface, but only with the payed version of vSphere. This forced me to always have a Windows VM running on some other machine.
  2. The integration of the vSphere tools into the OSX VM on the server did not work properly. So it was not ensured that the OSX VM is running which was important for some services.
  3. The integration of the vSphere server with my Eaton Battery was not directly possible.
  4. The backup of the vSphere server turned out to be a problem on the tooling side.

So: it was a nice try, but to have a sufficiently stable VM environment, I’d aim for some hosted VM server now.

MacMini as vSphere server

30. Januar 2013 um 17:19 | Veröffentlicht in Hardware, Software | Hinterlasse einen Kommentar

I have a Mac Mini (5,1 / Mid 2011), equipped with one hard drive, no superdrive, 16 GB of memory. It was running OS X 10.8 Server, and after some tries, I succeeded in creating a nice, small server for my network, including administration of all my iOS and OS X devices.

However, I also wanted some virtual machines to run on this machine. I used VMware Fusion first, and according to several instructions in the web, I reached out to have them start and stop when the server starts and stops.

Well, most of the times.

The other times, I got severe problems with the VMs. No way to have that construction as a productive business environment.

What to do?

Well, a friend of mine once showed me the power of VMware’s vSphere server. This made me pretty curious, and so I started to research if the Mac Mini is capable to run that stuff. And I found several pages, which made me hope.

So, next step was: create a Time Machine backup of my existing OS X Server installation.

Then: Get the (free) vSphere Hypervisor ISO image. Burn it onto a DVD.

Plug a superdrive (or something similar) to the Mac Mini, insert the DVD, reboot the Mac from the DVD.

Suspense…

And: it works. The vSphere installation comes up and runs through. Not bad, actually.

The only problem (and I was warned by the pages I read): The server does not particiapte in the network, because of missing drivers.

So: Download the driver from VMware’s website. Create a DVD with it on (I did not have CDs available). Put it into the superdrive. Mount it.

Does not work.

Tried around several possibilities, but no change: There’s no way for me to get the drivers from the DVD onto the Mac Mini’s harddrive. The funny thing is: The DVD is readable, you’ll see the folders, but no files in the folders. Weird!

Next try: Use a USB stick. Have one, formatted with FAT (well, one of its partitions). Put drivers on, stick it into the Mac Mini.

Does not work.

Searching the web. After multiple tries, I find the hint: FAT16.

Checking the stick: FAT32.

Reformatting the stick, putting drivers on it, plug it in – YIPPIEH! The stick is recognized by the vSphere system. Copy the drivers to their proper location, initiate their installation, reboot – GREAT!

On the way, there was another problem to solve: The Mac Mini tries to boot from the DVD, which is pretty crazy. The Option-key thing still works while the Mac plays it „bummmm“ sound, but next time, it will try the DVD again.

Here again, I learned something new about my Mac: You can press the CTRL key while the drive selection is on the screen. This way, you can define one of the drives to be always the startup drive.

NAS: Synology vs QNAP

6. Juli 2012 um 08:29 | Veröffentlicht in Hardware | Hinterlasse einen Kommentar
Schlagwörter: , , , , ,

Bislang hatte ich nur eine Synology DS410 unter DSM 4.0 laufen. Nachdem bei einem Kunden dessen Network Storage in die ewigen Jagdgründe eingegangen ist, habe ich mich dazu entschieden, mir ein zweites NAS zuzulegen, das als Backup für die Synology dienen sollte. Ausgewählt habe ich das QNAP TS-412 unter Firmware 3.7.1.

Um das gleich vorauszuschicken: In meiner Apple-Umgebung habe ich enorme Probleme bei der Konfiguration. Eine Verbindung mit meinem Lion Server-Open Directory konnte ich nicht herstellen – zwar wurden die Gruppen angezeigt, nicht aber die User („Floating forever“-Effekt). In den Foren konnte ich auch keine Lösung dafür finden.

Nachdem ich dann die Synology als LDAP-Server konfiguriert hatte, konnte ich per AFP auf die Netzwerk-Shares zugreifen. Nun aber trat ein weiterer, im Netz bereits intensiv diskutierter Effekt auf: Die Kopieroperationen sind seeehr laaangsaaam. Und zwar so langsam, daß sie unbrauchbar sind.

Ich habe mich also inzwischen von der Idee verabschiedet, die Serverstrukturen auf dem QNAP neu einzurichten, die Daten dorthin zu migrieren und danach die Synology für Backups zu nutzen. Das QNAP wird also tatsächlich nur einen lokalen Nutzer für Backups besitzen und als „dummer“ Empfänger von Backups dienen.

Eigentlich schade, denn beim QNAP lassen sich manche Dinge einfacher über die Oberfläche regeln, als das bei der Synology der Fall ist. Offenkundig ist die Synology aber ausgereifter und – zumindest für Apple-Infrastrukturen – die bessere Wahl.

Einrichten eines Reiner SCT unter Linux

25. Februar 2012 um 19:48 | Veröffentlicht in Hardware, Software | Hinterlasse einen Kommentar
Schlagwörter: , , , , , , ,

Ich habe mir einen Reiner SCT Kartenleser (CyberJack RFID Standard) besorgt, um mit Hilfe einer D-Trust-Signaturkarte die damit möglichen Dienste (z.B. Mail-Verschlüsselung) auf meinem Mac, sowie den darauf laufenden Virtuellen Maschinen nutzen zu können. Eine Spezialfrage ist, inwieweit ich die vorhandenen Schlüssel dafür nutzen kann, abgeleitete Zertifikate (z.B. für einen Intranet-Server) zu erstellen.

Die Recherche nach möglichen Lösungen erwies sich als nicht ganz trivial, und daher möchte ich hier beschreiben, wie ich Schritt für Schritt vorgegangen bin (bzw. noch vorgehe, denn die Sache ist derzeit noch im Fluss und weitere Updates werden folgen).

1. Einrichten des Kartenlesers auf dem Mac

Dies ist ist relativ schnell und einfach erledigt. Reiner SCT stellt hierfür ein Installationspaket zur Verfügung:

Gerätetreiber für cyberJack® RFID standard für das Betriebssystem Apple Mac OS X.

Diese Treiber ermöglichen es bereits, z.B. mit BankX 4.2.8 und einer entsprechenden HBCI-Karte ein abgesichertes Online-Banking zu betreiben.

(Dieser Anwendungsfall war übrigens der Start meiner Versuche mit Kartenlesern, zu Beginn hatte ich einen Reiner SCT Decoder, der eigentlich gute Dienste geleistet hat, für die neuen Anwendungen aber nicht geeignet ist.)

2. Einrichten des Kartenleser unter Linux

Hier wurde es etwas tricky. Zunächst hatte ich versucht, mit Hilfe einiger Open Source-Pakete unter OSX direkten Zugriff auf die Signaturkarte zu bekommen. Dies hat aber nicht sauber funktioniert, und die Zeit und das Know-how, hier in die Tiefe zu gehen, habe ich leider nicht.

Daher wählte ich den Weg über eine kleine Virtuelle Maschine mit Ubuntu Linux 10.04 Desktop, die ich „mal schnell“ aufsetzte. Mit VirtualBox gibt es einen schnellen und kostenlosen Weg, sich Linux auf den Mac zu holen.

2.1. Pakete installieren

Über das Menü System > Administration > Synaptic Paket Manager wird der Paketmanager gestartet. Hier wählen Sie die folgenden Pakete aus:

  • opensc
  • pcsc-tools
  • libccid
  • libengine-pkcs11-openssl

2.2. Kartenleser mit der VM verbinden

Verbinden Sie nun den Kartenleser über Ihren Parallelisierer (z.B. VirtualBox) mit der virtuellen Maschine. Fragen Sie dann unter Linux ab, ob der Kartenleser via USB zur Verfügung steht:

administrator@ivm-1:~$ lsusb
 Bus 002 Device 002: ID 0c4b:0500 Reiner SCT Kartensysteme GmbH
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 002: ID 203a:fff9
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 administrator@ivm-1:~$

2.3. Reiner-Treiber installieren

Auch für Linux benötigen wir noch einen speziellen Treiber. Zunächst holen wir uns diesen direkt von der Reiner SCT-Seite, dann installieren wir ihn:

administrator@ivm-1:~$ wget http://support.reiner-sct.de/downloads/LINUX/V3.99.5_SP03/libifd-cyberjack6_3.99.5final.SP03_amd64_u1004.deb
administrator@ivm-1:~$ sudo dpkg -i libifd-cyberjack6_3.99.5final.SP03_amd64_u1004.deb

2.4. Prüfen, ob der Kartenleser von OpenSC erkannt wird

Dazu rufen wir erstmalig die OpenSC-Tools auf:

administrator@ivm-1:~$ opensc-tool --list-readers
Readers known about:
Nr.    Driver     Name
0      pcsc       REINER SCT cyberJack RFID standard (8071123203) 00 00

2.5. OpenSC konfigurieren

Mit der voreingestellten Konfigurationsdatei von OpenSC hatte ich einige Schwierigkeiten, die durch einige Anpassungen behoben werden konnten:

administrator@ivm-1:~$ cd /etc/opensc
administrator@ivm-1:~$ sudo vi opensc.conf

Eintrag für reader_drivers anpassen:

# reader_drivers = openct, pcsc, ctapi;
reader_drivers = pcsc;

Definition für den Treiber pcsc anpassen, sollte danach wie folgt aussehen:

 # Define parameters specific to your readers.
 # The following section shows definitions for PC/SC readers,
 # but the same set of variables are applicable to ctapi and
 # openct readers, simply by using "reader_driver ctapi" and
 # "reader_driver openct", respectively.
 reader_driver pcsc {
 # This sets the maximum send and receive sizes.
 # Some reader drivers have limitations, so you need
 # to set these values. For usb devices check the
 # properties with lsusb -vv for dwMaxIFSD
 #
 # max_send_size = 252;
 # max_recv_size = 252;
 #
 # Connect to reader in exclusive mode.
 # Default: false
 # connect_exclusive = true;
 #
 # Reset the card after disconnect.
 # Default: true
 # connect_reset = false;
 #
 # Reset the card after each transaction.
 # Default: false
 # transaction_reset = true;
 #
 # Enable pinpad if detected (PC/SC v2.0.2 Part 10)
 # Default: false
 enable_pinpad = true;
 #
 # Use specific pcsc provider.
 # Default: /lib/libpcsclite.so.1
 provider_library = /lib/libpcsclite.so.1
 }

Dann den PCSC-Treiber beim Laden erzwingen:

 # Force using specific card driver
 #
 # If this option is present, OpenSC will use the supplied
 # driver with all inserted cards.
 #
 # Default: autodetect
 #
 force_card_driver = pcsc;

Die übrigen Einstellungen können unverändert bleiben.

2.6. Testen von Leser und Karte

Nun können wir prüfen, ob auf den Leser und die Karte korrekt zugegriffen werden kann. Zunächst fragen wir einige Leser-Parameter ab (die Ergebnisdaten sind natürlich verändert, ich gebe hier ja keine Privatissima preis…):

administrator@ivm-1:~$ opensc-tool --reader 0 --atr
3c:fe:28:20:32:a1:2a:f1:ee:28:c8:08:74

administrator@ivm-1:~$ opensc-tool --reader 0 --name
CardOS M4

Dann sehen wir uns an, was die Karte zu bieten hat:

administrator@ivm-1:~$ pkcs15-tool -D
 Using reader with a card: REINER SCT cyberJack RFID standard (8071123203) 00 00
 PKCS#15 Card [D-TRUST card 2.4 2ca]:
 Version : 1
 Serial number : 1921104480AF
 Manufacturer ID: XXX GmbH (C)
 Flags : Login required, PRN generation

PIN [Card PIN]
 Com. Flags: 0x3
 ID : 01
 Flags : [0x31], case-sensitive, initialized, needs-padding
 Length : min_len:8, max_len:8, stored_len:8
 Pad char : 0x00
 Reference : 1
 Type : UTF-8
 Path :

PIN [Signature PIN (SigG)]
 Com. Flags: 0x3
 ID : 04
 Flags : [0x33], case-sensitive, local, initialized, needs-padding
 Length : min_len:8, max_len:8, stored_len:8
 Pad char : 0x00
 Reference : -127
 Type : UTF-8
 Path : 3a002faf

PIN [Card PUK]
 Com. Flags: 0x3
 ID : 02
 Flags : [0x79], case-sensitive, unblock-disabled, initialized, needs-padding, unblockingPin
 Length : min_len:8, max_len:8, stored_len:8
 Pad char : 0x00
 Reference : 0
 Type : UTF-8
 Path :

PIN [Signature PUK (SigG)]
 Com. Flags: 0x3
 ID : 0a
 Flags : [0x7B], case-sensitive, local, unblock-disabled, initialized, needs-padding, unblockingPin
 Length : min_len:8, max_len:8, stored_len:8
 Pad char : 0x00
 Reference : 0
 Type : UTF-8
 Path : 3e002faf

Private RSA Key [XXX Authentication Key]
 Com. Flags : 1
 Usage : [0x26], decrypt, sign, unwrap
 Access Flags: [0x0]
 ModLength : 2048
 Key ref : 1
 Native : yes
 Path : 4f10521350734b02
 Auth ID : 01
 ID : 029b725feb62cac12e9284b9a782d0dc

Private RSA Key [SigG Signature Key]
 Com. Flags : 1
 Usage : [0x204], sign, nonRepudiation
 Access Flags: [0x0]
 ModLength : 2048
 Key ref : 2
 Native : yes
 Path : 3e010afe
 Auth ID : 04
 ID : 000103030205A60702090F0b0c0d0e0f

X.509 Certificate [XXX Authentication Certificate]
 Flags : 2
 Authority: no
 Path : 3e01601583064901
 ID : 029b715efb64d1d12e9584d9c782d0dc

X.509 Certificate [SigG Signature Certificate]
 Flags : 2
 Authority: no
 Path : 3f015025570444a1
 ID : 000102030405060708090a0b0c0d0e0f

X.509 Certificate []
 Flags : 0
 Authority: no
 Path : 3f0250258374c70d
 ID : 2d353234361635373909353302234323733343235

X.509 Certificate []
 Flags : 0
 Authority: no
 Path : 3f0050154304c00e
 ID : 31363233363431313430323038303632393334

X.509 Certificate []
 Flags : 0
 Authority: no
 Path : 3f0050154304c708
 ID : 32343434393437353132393931373030393939

X.509 Certificate []
 Flags : 0
 Authority: no
 Path : 3f0050154304c008
 ID : 39313935373536313139373033333132383839

3. Weitere Informationen

Hier noch einige Links zu den relevanten Seiten:
Reiner SCT - Linuxtreiber: http://www.reiner-sct.com/index.php?option=content&task=view&id=243
Ubuntu Forums - Howto: http://ubuntuforums.org/showthread.php?t=1557180
OpenSC-Project - QuickStart: http://www.opensc-project.org/opensc/wiki/QuickStart

Erstelle kostenlos eine Website oder ein Blog auf WordPress.com.
Entries und Kommentare feeds.