6.01.2015

Slow PPTP VPN speed over wifi on D-Link WNR3500Lv2 wireless router

I recently bought a new D-Link WNR3500Lv2 wireless (802.11 b/g/n) router. It is nice and fast over the wire and through the wifi connection, however, when I connect to my work VPN (PPTP conn), things slow to a halt. Now, because it's VPN, it's going to be slow, but the connection was basically unresponsively slow. After a month, I finally figured things out, even though it doesn't make since at all to me (especially since the wireless connection is fine without the VPN, it shouldn't matter). I changed the speed to "up to 54 Mbps" in the wireless settings section in the router, and now it's nice and fast. It was on the default setting of "up to 145 Mbps" before that, which switches between g and n modes I believe. I haven't tried "up to 300 Mbps" (100% 802.11n) because I have g devices in the house, but I assume it would also be okay for the VPN.

7.01.2014

How to install/set-up OpenWrt on a D-Link DIR-505L wireless router

This guide is more for myself, but feel free to ask questions.

OpenWrt wiki page for the DIR-505: http://wiki.openwrt.org/toh/d-link/dir-505

A. Basic setup and housekeeping:

Follow steps B thru E in this guide: https://dl.dropboxusercontent.com/u/57289645/blog/dir-505l_openwrt_setup_guide.txt

# ethernet
uci set network.wan=interface
uci set network.wan.proto=dhcp
uci set network.wan.ifname=eth1
uci del network.lan.ifname
# wifi
uci set wireless.@wifi-device[0].disabled=0
uci set wireless.@wifi-iface[0].ssid="your_ssid"
uci set wireless.@wifi-iface[0].encryption="psk2"
uci set wireless.@wifi-iface[0].key="your_password"
# system
uci set system.@system[0].hostname="your_hostname"
uci set system.@system[0].timezone="PST8PDT,M3.2.0,M11.1.0" # Los Angeles
# commit changes
uci commit
wifi

Sources:
https://forum.openwrt.org/viewtopic.php?pid=230861#p230861
http://wiki.openwrt.org/doc/uci/wireless/encryption#configure.wpa2.psk
http://wiki.openwrt.org/doc/uci/system

B. USB storage support (assuming NTFS-formatted USB stick):

opkg update
opkg install kmod-usb-storage kmod-fs-ntfs ntfs-3g
mkdir -p /mnt/usb_drive
ntfs-3g /dev/sda1 /mnt/usb_drive -o rw,sync
# do stuff
umount /dev/sda1

Sources:
http://wiki.openwrt.org/doc/howto/usb.essentials
http://wiki.openwrt.org/doc/howto/usb.storage
http://wiki.openwrt.org/doc/howto/writable_ntfs

C. USB serial adapter support:

opkg update
opkg install kmod-usb-serial coreutils-stty
opkg install kmod-usb-serial-pl2303 # for Prolific PL2303-based devices
opkg install kmod-usb-acm # for devices using Abstract Control Model (ACM)
# reboot here
cat /dev/ttyUSB0 # view data coming to the serial port
stty -F /dev/ttyUSB0 -a # view serial port settings

Source:
http://wiki.openwrt.org/doc/hardware/port.serial#usb.enabled.routers

D. Minimal Python install with pyserial support

opkg update
opkg install python-mini pyserial
# termios.so is missing so we need to copy it from the full package
cd /tmp
opkg download python
tar -xzf python_*.ipk ./data.tar.gz
tar -xzf data.tar.gz ./usr/lib/python2.7/lib-dynload/termios.so -C /

Source:
http://kelvinsthunderstorm.com/omnimaopenwrt-and-xbee/

6.09.2014

Simple Fortran/C interoperability example using Fortran 2003

The following is a simple example of how Fortran (2003) and C computer languages can mix. Fortran 2003 introduced an intrinsic module called ISO_C_BINDING that provides kind constants for common C types, e.g. double == C_DOUBLE kind. By using an interface block and linking to a C object file, you can use C code in your Fortran projects. The "bind(C)" statement and "value" attribute are also parts of Fortran 2003; the first tells the compiler to bind that subroutine to the C function, and the second tells the compiler to use call by value instead of call by reference (the latter is the default for Fortran). test.f90:

program main

implicit none

interface
   subroutine print_string(string, length) bind(C)
      use, intrinsic :: iso_c_binding, only: C_CHAR, C_INT
      implicit none
      character(kind=C_CHAR), intent(in) :: string(*)
      ! value attribute == call by value instead of by reference
      integer(kind=C_INT), value, intent(in) :: length
   end subroutine print_string
end interface

call my_print_string("Hello, world!")

contains

! wrapper function to pass string and its length to C function
subroutine my_print_string(string)
   use, intrinsic :: iso_c_binding, only: C_CHAR
   implicit none
   character(kind=C_CHAR, len=*), intent(in) :: string
   call print_string(string, len(string))
end subroutine my_print_string

end program main

test.c:

#include <stdio.h>

void print_string(const char* str, const int len)
{
   // Fortran doesn't use null-terminated strings
   int i;
   for (i = 0; i < len; i++)
      putchar(str[i]);
}

Compile:

cc -c test.c
f95 -std=f2003 test.f90 test.o

$ ./a.out
Hello, world!