Wl1251-cal

rough pseudocode for what wl1251-cal seems to be doing:
wl1251str *handle = libwl1251_init("wlan0",0);
send dbus message "com.nokia.phone.net" "/com/nokia/phone/net" "Phone.Net" "get_registration_status"
set country code to uint32 argument 5 of dbus message

wlan-tx-cost3_0 cal data is the nvs data
default nvs data is in /lib/firmware/wl1251-nvs.bin

flag in r9 controls special change to nvs data.
If there is a dbus error/problem or if country code is 0, r9 is set to 2

if country code is obtained then it checks for FCC country (302, 310, 311, 316, 312, 313, 314, 315, 332, 466, 724, 722, 334, 732) and if so, sets r9 to 2 else it sets r9 to 1

If r9 is not set to 1, nvs data is changed as follows:
nvsdata[151] = 2
nvsdata[154] = 9
nvsdata[179] = 2
nvsdata[17C] = 9

nvs data is sent via 
libwl1251_nvs_push(handle,nvsdata+4,0x2F0) //return value <= 0 indicates error)

after nvs stuff this is done
dbus message is sent "com.nokia.SystemInfo" "/com/nokia/SystemInfo" "com.nokia.SystemInfo" "GetConfigValue" with argument passed in "/certs/npc/esn/wlan_id"

Also able to read wlan mac address from cal by reading wlan-mac
Then it uses SIOCSIFHWADDR ioctl to set MAC address.

next, if r9 is 1, set r10 to "EU" else set r10 to "US"

Then its calling nl functions and sending a command (via genlmsg_put) with message 27. "nl80211" is passed to genl_ctrl_search_by_name and then genl_family_get_id to obtain family ID.
Flags, seq, hdrlen and version parameters for genlmsg_put are all zero.
pid comes from getpid.
Its calling nla_put(33,3,r10) before it sends the message
Its registering some callbacks via nl_cb_err and nl_cb_set
It then appears to loop around with a nl_recvmsgs call in the middle waiting for a callback to trip.
none of the 3 handlers seem to be doing anything specifically fancy.

After the nl_recvmsgs loop finishes, the function ends.

libwl1251_nvs_push simply loads the nvs data to the card.
not sure whether anything special is done by libwl1251_init