hilink

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 18 Imported by: 0

README

Package hilink is a Go package for working with Huawei Hilink devices (ie, 3G/4G modems and WiFi access devices).

Installation

Install in the normal way:

$ go get -u github.com/kenshaw/hilink

Usage

To use the Go API, please see the full API information on Go ref.

There is a convenient command line tool, hlcli that makes working with the API extremely easy:

# install hlcli tool
$ go get -u github.com/kenshaw/hilink/cmd/hlcli

# display available commands
$ hlcli help

# get help for a subcommand 'smslist'
$ hlcli help smslist
$ hlcli smslist --help

# get network connection information from non-standard API endpoint
$ hlcli networkinfo -endpoint http://192.168.245.1/

# send sms with verbose output
$ hlcli smssend -to='+62....' -msg='your message' -v

# send ussd code with verbose output
$ hlcli ussdcode -code -v

Notes

This was built for interfacing with a Huawei E3370h-153 (specifically a Megafon M150-2) device, popular in Europe and Asia. It was flashed using a custom firmware and WebUI that enables the extra features.

Here is the relevant information taken from the API using the hinfo tool:

$ cd $GOPATH/src/github.com/kenshaw/hilink
$ go build ./cmd/hinfo/ && ./hinfo
{
  "Classify": "hilink",
  "DeviceName": "E3370",
  "HardwareVersion": "CL2E3372HM",
  <<sensitive information omitted>>
  "Msisdn": "",
  "ProductFamily": "LTE",
  "SoftwareVersion": "22.200.09.01.161",
  "WebUIVersion": "17.100.11.00.03-Mod1.0",
  "supportmode": "LTE|WCDMA|GSM",
  "workmode": "LTE"
}

TODO

This API is currently incomplete, as I only have one type of Hilink device to test with and because I have not attempted to do an exhaustive list of all API calls. That said, it should be fairly easy to write a new API call by following the existing code. Pull requests are greatly appreciated, and encouraged!

Because the documentation available for the E3372h-153 is so poor, especially for the version that I have (M150-2, identified by the "HardwareVersion" of CL2E3372HM), and very little is available in English, I have decided for posterity to record my notes on installing modified firmware here. These notes should also work for other Huawei devices, but make sure you are using the correct firmware for your device! Incorrectly flashing your Hilink device, or using the wrong firmware will likely brick your device.

Huawei modems with older firmware (circa 2014 and older) are commonly referred to as "stick" devices. These devices can sometimes be flashed with the newer "hilink" firmware versions, however as I only have one hardware revision available to me, I cannot definitely say which can or cannot be flashed. My rudimentary investigation leads me to believe that the vast majority of the Huawei modems on the market can be updated to a Hilink version of the firmware.

For reference, all "stick" firmware starts with "21." and all hilink firmware starts with "22." While some people have had success with getting the stick firmware to work properly with Linux, I personally have not been successful doing that. Additionally, those who have reported getting the stick firmware to work, have reported significantly lower than 4G speeds.

The primary difference between "stick" and "hilink" firmware, is that the stick firmware exposes standard serial ports to the host that work as standard modems. These also have a standard tty interface that one can access and control the internals. The "hilink" firmware instead provides a standard USB ethernet device, with its own subnett'd network and exposes a web interface for controlling the software over the ethernet device. By default, that network provides standard DHCP and is configured to issue addresses in the range of 192.168.8.100-200.

Note that a hilink device can be put into "debug" mode which then exposes a number of standard /dev/ttyUSB* that can then be used to send AT commands. This can be done by using this API or by using the usb_modeswitch command line tool. Please see Go ref or the usb_modeswitch manpage.

USB Modeswitching

Occassionally when a hilink device is plugged in, the Linux kernel/udev does not recognize it, and does not properly put the device into hilink mode. The latest versions of usb_modeswitch are able to deal with this:

$ sudo usb_modeswitch -v 12d1 -p 1f01 -V 12d1 -P 14dc -J

Megafon M150-2 (aka E3372h-153, aka hw rev. CL2E3372HM)

The Huawei E3372h-153 device is a 4G LTE USB modem that works with with all international 4G frequencies. The same hardware is sold as a "stick" model and a "hilink" model -- please see the comments above. Other companies may distribute this same hardware version under other names, and will usually be labeled a E3372h-153 device. I am not sure if the -153 is specific only to Megafon or not, as I have seen others listed (but have not bought) with that model number.

If it is sold as a "stick" model (sometimes listed on the packaging as a E3372s) then it will have the older firmware, and will need to be flashed / updated. Additionally, the stock firmware is missing many useful features, and should be flashed to a modified firmware version.

Flashing a CL2E3372HM with modified firmware
  1. Write down the IMEI number listed on the modem (needed if it is running the 'stick' firmware)
  2. Boot into Windows and plug the CL2E3372HM into the system
  3. Download all the files here
  4. Extract MobileBrServ.rar and as an Administrator, execute the extracted mbbServiceSetup.exe. Follow the prompts to install (if any)
  5. Extract E3372h-607_Update_21.110.99.02.00.rar and as an Administrator, execute the extracted E3372h-607_Update_21.110.99.02.00.exe. Follow the prompts. If there is an error, unplug the CL2E3372HM and plug it in again. Wait until Windows recognizes the device and try again
  6. If the existing version of the firmware is a 'stick' firmware, you will be prompted for a flash unlock code. You can use this tool to generate an unlock code. Enter the unlock code and continue following the prompts
  7. Extract E3372h-153_Update_22.200.09.01.161_M_AT_01.rar and as an Administrator, execute the extracted E3372h-153_Update_22.200.09.01.161_M_AT_01.exe. Follow the prompts
  8. Extract Update_WEBUI_17.100.11.00.03_forE3372_Mod1.0.rar and as an Administrator, execute the extracted Update_WEBUI_17.100.11.00.03_forE3372_Mod1.0.exe. Follow the prompts

Documentation

Overview

Package hilink provides a Hilink WebUI client.

Index

Constants

View Source
const (
	// DefaultURL is the default URL endpoint for the Hilink WebUI.
	DefaultURL = "http://192.168.8.1/"
	// DefaultTimeout is the default timeout.
	DefaultTimeout = 10 * time.Second
	// TokenHeader is the header used by the WebUI for CSRF tokens.
	TokenHeader = "__RequestVerificationToken"
)

Variables

This section is empty.

Functions

func ErrorCodeMap

func ErrorCodeMap() map[int]string

ErrorCodeMap contains the known message strings for Hilink devices.

see: http://www.bez-kabli.pl/viewtopic.php?t=42168

func ErrorMessageFromString

func ErrorMessageFromString(code string) string

ErrorMessageFromString returns the error message from a string version of the error code.

func SimpleRequestXML

func SimpleRequestXML(vals ...string) []byte

SimpleRequestXML creates an XML string from value pairs.

Unfortunately the XML parser (or whatever underyling code) included with the WebUI on Hilink devices expects parameters in a specific order. This makes packages like mxj or other map based solutions not feasible for use, as Go has random key ordering for maps.

On another note, XML sucks.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client represents a Hilink client connection.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new client a Hilink device.

func (*Client) AutorunVersion

func (cl *Client) AutorunVersion(ctx context.Context) (string, error)

AutorunVersion retrieves device autorun version.

func (*Client) Connect

func (cl *Client) Connect(ctx context.Context) (bool, error)

Connect connects the Hilink device to the network provider.

func (*Client) ConnectionInfo

func (cl *Client) ConnectionInfo(ctx context.Context) (XMLData, error)

ConnectionInfo retrieves connection (dialup) information.

func (*Client) CradleMAC

func (cl *Client) CradleMAC(ctx context.Context) (string, error)

CradleMAC retrieves cradle MAC address.

func (*Client) CradleMACSet

func (cl *Client) CradleMACSet(ctx context.Context, addr string) (bool, error)

CradleMACSet sets the MAC address for the cradle.

func (*Client) CradleStatusInfo

func (cl *Client) CradleStatusInfo(ctx context.Context) (XMLData, error)

CradleStatusInfo retrieves cradle status information.

func (*Client) DdnsList

func (cl *Client) DdnsList(ctx context.Context) (XMLData, error)

DdnsList retrieves list of DDNS providers.

func (*Client) DeviceBackup

func (cl *Client) DeviceBackup(ctx context.Context) (string, error)

DeviceBackup backups device configuration and retrieves backed up configuration data as a base64 encoded string.

func (*Client) DeviceBasicInfo

func (cl *Client) DeviceBasicInfo(ctx context.Context) (XMLData, error)

DeviceBasicInfo retrieves basic device information.

func (*Client) DeviceConfig

func (cl *Client) DeviceConfig(ctx context.Context) (XMLData, error)

DeviceConfig retrieves device configuration.

func (*Client) DeviceControl

func (cl *Client) DeviceControl(ctx context.Context, code uint) (bool, error)

DeviceControl sends a control code to the device.

func (*Client) DeviceFeatures

func (cl *Client) DeviceFeatures(ctx context.Context) (XMLData, error)

DeviceFeatures retrieves device feature information.

func (*Client) DeviceInfo

func (cl *Client) DeviceInfo(ctx context.Context) (XMLData, error)

DeviceInfo retrieves general device information.

func (*Client) DeviceModeSet

func (cl *Client) DeviceModeSet(ctx context.Context, mode uint) (bool, error)

DeviceModeSet sets the device mode (0-project, 1-debug).

func (*Client) DeviceReboot

func (cl *Client) DeviceReboot(ctx context.Context) (bool, error)

DeviceReboot restarts the device.

func (*Client) DeviceReset

func (cl *Client) DeviceReset(ctx context.Context) (bool, error)

DeviceReset resets the device configuration.

func (*Client) DeviceShutdown

func (cl *Client) DeviceShutdown(ctx context.Context) (bool, error)

DeviceShutdown shuts down the device.

func (*Client) DhcpConfig

func (cl *Client) DhcpConfig(ctx context.Context) (XMLData, error)

DhcpConfig retrieves DHCP configuration.

func (*Client) Disconnect

func (cl *Client) Disconnect(ctx context.Context) (bool, error)

Disconnect disconnects the Hilink device from the network provider.

func (*Client) DmzConfig

func (cl *Client) DmzConfig(ctx context.Context) (XMLData, error)

DmzConfig retrieves DMZ status and IP address of DMZ host.

func (*Client) DmzConfigSet

func (cl *Client) DmzConfigSet(ctx context.Context, enabled bool, dmzIPAddress string) (bool, error)

DmzConfigSet enables or disables the DMZ and the DMZ IP address of the device.

func (*Client) Do

func (cl *Client) Do(ctx context.Context, path string, v interface{}) (XMLData, error)

Do sends a request to the server with the provided path. If data is nil, then GET will be used as the HTTP method, otherwise POST will be used.

func (*Client) FastbootFeatures

func (cl *Client) FastbootFeatures(ctx context.Context) (XMLData, error)

FastbootFeatures retrieves fastboot feature information.

func (*Client) FirewallFeatures

func (cl *Client) FirewallFeatures(ctx context.Context) (XMLData, error)

FirewallFeatures retrieves firewall security feature information.

func (*Client) GlobalConfig

func (cl *Client) GlobalConfig(ctx context.Context) (XMLData, error)

GlobalConfig retrieves global Hilink configuration.

func (*Client) GlobalFeatures

func (cl *Client) GlobalFeatures(ctx context.Context) (XMLData, error)

GlobalFeatures retrieves global feature information.

func (*Client) Language

func (cl *Client) Language(ctx context.Context) (string, error)

Language retrieves current language.

func (*Client) LanguageSet

func (cl *Client) LanguageSet(ctx context.Context, lang string) (bool, error)

LanguageSet sets the language.

func (*Client) LogInfo

func (cl *Client) LogInfo(ctx context.Context) (XMLData, error)

LogInfo retrieves current log setting information.

func (*Client) LogPath

func (cl *Client) LogPath(ctx context.Context) (string, error)

LogPath retrieves device log path (URL).

func (*Client) ModeInfo

func (cl *Client) ModeInfo(ctx context.Context) (XMLData, error)

ModeInfo retrieves network mode settings information.

func (*Client) ModeList

func (cl *Client) ModeList(ctx context.Context) (XMLData, error)

ModeList retrieves available network modes.

func (*Client) ModeNetworkInfo

func (cl *Client) ModeNetworkInfo(ctx context.Context) (XMLData, error)

ModeNetworkInfo retrieves current network mode information.

func (*Client) ModeSet

func (cl *Client) ModeSet(ctx context.Context, netMode, netBand, lteBand string) (bool, error)

ModeSet sets the network mode.

func (*Client) MonthInfo

func (cl *Client) MonthInfo(ctx context.Context) (XMLData, error)

MonthInfo retrieves the month download statistic information.

func (*Client) NatType

func (cl *Client) NatType(ctx context.Context) (XMLData, error)

NatType retrieves NAT type.

func (*Client) NatTypeSet

func (cl *Client) NatTypeSet(ctx context.Context, ntype uint) (bool, error)

NatTypeSet sets NAT type (values: 0, 1).

func (*Client) NetworkInfo

func (cl *Client) NetworkInfo(ctx context.Context) (XMLData, error)

NetworkInfo retrieves network provider information.

func (*Client) NetworkTypes

func (cl *Client) NetworkTypes(ctx context.Context) (XMLData, error)

NetworkTypes retrieves available network types.

func (*Client) NewSessionAndTokenID

func (cl *Client) NewSessionAndTokenID(ctx context.Context) (string, string, error)

NewSessionAndTokenID starts a session with the server, and returns the session and token.

func (*Client) NotificationInfo

func (cl *Client) NotificationInfo(ctx context.Context) (XMLData, error)

NotificationInfo retrieves notification information.

func (*Client) PCAssistantConfig

func (cl *Client) PCAssistantConfig(ctx context.Context) (XMLData, error)

PCAssistantConfig retrieves PC Assistant configuration.

func (*Client) PhonebookCount

func (cl *Client) PhonebookCount(ctx context.Context) (XMLData, error)

PhonebookCount retrieves count of phonebook entries per group.

func (*Client) PhonebookCreate

func (cl *Client) PhonebookCreate(ctx context.Context, group uint, name, phone string, sim bool) (XMLData, error)

PhonebookCreate creates a new phonebook entry.

func (*Client) PhonebookDelete

func (cl *Client) PhonebookDelete(ctx context.Context, id uint) (bool, error)

PhonebookDelete deletes a specified phonebook entry.

func (*Client) PhonebookGroupList

func (cl *Client) PhonebookGroupList(ctx context.Context, page, count uint, sortByName, ascending bool) (XMLData, error)

PhonebookGroupList retrieves list of the phonebook groups.

func (*Client) PhonebookImport

func (cl *Client) PhonebookImport(ctx context.Context, group uint) (XMLData, error)

PhonebookImport imports SIM contacts into specified phonebook group.

func (*Client) PhonebookList

func (cl *Client) PhonebookList(ctx context.Context, group, page, count uint, sim, sortByName, ascending bool, keyword string) (XMLData, error)

PhonebookList retrieves list of phonebook entries from a specified group.

func (*Client) PinActivate

func (cl *Client) PinActivate(ctx context.Context, pin string) (bool, error)

PinActivate activates a SIM PIN.

func (*Client) PinChange

func (cl *Client) PinChange(ctx context.Context, pin, new string) (bool, error)

PinChange changes a SIM PIN.

func (*Client) PinDeactivate

func (cl *Client) PinDeactivate(ctx context.Context, pin string) (bool, error)

PinDeactivate deactivates a SIM PIN.

func (*Client) PinEnter

func (cl *Client) PinEnter(ctx context.Context, pin string) (bool, error)

PinEnter enters a SIM PIN.

func (*Client) PinEnterPuk

func (cl *Client) PinEnterPuk(ctx context.Context, puk, new string) (bool, error)

PinEnterPuk enters a SIM PIN puk.

func (*Client) PinInfo

func (cl *Client) PinInfo(ctx context.Context) (XMLData, error)

PinInfo retrieves SIM PIN status information.

func (*Client) PinSaveInfo

func (cl *Client) PinSaveInfo(ctx context.Context) (XMLData, error)

PinSaveInfo retrieves SIM PIN save information.

func (*Client) PinSimlockInfo

func (cl *Client) PinSimlockInfo(ctx context.Context) (XMLData, error)

PinSimlockInfo retrieves SIM lock information.

func (*Client) PowerFeatures

func (cl *Client) PowerFeatures(ctx context.Context) (XMLData, error)

PowerFeatures retrieves power feature information.

func (*Client) ProfileInfo

func (cl *Client) ProfileInfo(ctx context.Context) (XMLData, error)

ProfileInfo retrieves profile information (ie, APN).

func (*Client) PublicKey

func (cl *Client) PublicKey(ctx context.Context) (string, error)

PublicKey retrieves webserver public key.

func (*Client) SetSessionAndTokenID

func (cl *Client) SetSessionAndTokenID(sessionID, tokenID string) error

SetSessionAndTokenID sets the sessionID and tokenID for the Client.

func (*Client) SignalInfo

func (cl *Client) SignalInfo(ctx context.Context) (XMLData, error)

SignalInfo retrieves network signal information.

func (*Client) SimInfo

func (cl *Client) SimInfo(ctx context.Context) (XMLData, error)

SimInfo retrieves SIM card information.

func (*Client) SipAlg

func (cl *Client) SipAlg(ctx context.Context) (XMLData, error)

SipAlg retrieves status and port of the SIP application-level gateway.

func (*Client) SipAlgSet

func (cl *Client) SipAlgSet(ctx context.Context, port uint, enabled bool) (bool, error)

SipAlgSet enables/disables SIP application-level gateway and sets SIP port.

func (*Client) SmsConfig

func (cl *Client) SmsConfig(ctx context.Context) (XMLData, error)

SmsConfig retrieves device SMS configuration.

func (*Client) SmsCount

func (cl *Client) SmsCount(ctx context.Context) (XMLData, error)

SmsCount retrieves count of SMS per inbox type.

func (*Client) SmsDelete

func (cl *Client) SmsDelete(ctx context.Context, id uint) (bool, error)

SmsDelete deletes a specified SMS.

func (*Client) SmsFeatures

func (cl *Client) SmsFeatures(ctx context.Context) (XMLData, error)

SmsFeatures retrieves SMS feature information.

func (*Client) SmsList

func (cl *Client) SmsList(ctx context.Context, boxType, page, count uint, sortByName, ascending, unreadPreferred bool) (XMLData, error)

SmsList retrieves list of SMS in an inbox.

func (*Client) SmsReadSet

func (cl *Client) SmsReadSet(ctx context.Context, id string) (bool, error)

SmsReadSet sets the read status of a SMS.

func (*Client) SmsSend

func (cl *Client) SmsSend(ctx context.Context, msg string, to ...string) (bool, error)

SmsSend sends an SMS.

func (*Client) SmsSendStatus

func (cl *Client) SmsSendStatus(ctx context.Context) (XMLData, error)

SmsSendStatus retrieves SMS send status information.

func (*Client) StatusInfo

func (cl *Client) StatusInfo(ctx context.Context) (XMLData, error)

StatusInfo retrieves general device status information.

func (*Client) TetheringFeatures

func (cl *Client) TetheringFeatures(ctx context.Context) (XMLData, error)

TetheringFeatures retrieves USB tethering feature information.

func (*Client) TrafficClear

func (cl *Client) TrafficClear(ctx context.Context) (bool, error)

TrafficClear clears the current traffic statistics.

func (*Client) TrafficInfo

func (cl *Client) TrafficInfo(ctx context.Context) (XMLData, error)

TrafficInfo retrieves traffic statistic information.

func (*Client) Upnp

func (cl *Client) Upnp(ctx context.Context) (XMLData, error)

Upnp retrieves the status of UPNP.

func (*Client) UpnpSet

func (cl *Client) UpnpSet(ctx context.Context, enabled bool) (bool, error)

UpnpSet enables/disables UPNP.

func (*Client) UssdCode

func (cl *Client) UssdCode(ctx context.Context, code string) (bool, error)

UssdCode sends a USSD code to the Hilink device.

func (*Client) UssdContent

func (cl *Client) UssdContent(ctx context.Context) (string, error)

UssdContent retrieves content buffer of the active USSD session.

func (*Client) UssdRelease

func (cl *Client) UssdRelease(ctx context.Context) (bool, error)

UssdRelease releases the active USSD session.

func (*Client) UssdStatus

func (cl *Client) UssdStatus(ctx context.Context) (UssdState, error)

UssdStatus retrieves current USSD session status information.

func (*Client) WebUIConfig

func (cl *Client) WebUIConfig(ctx context.Context) (XMLData, error)

WebUIConfig retrieves WebUI configuration.

func (*Client) WifiFeatures

func (cl *Client) WifiFeatures(ctx context.Context) (XMLData, error)

WifiFeatures retrieves wifi feature information.

func (*Client) WlanConfig

func (cl *Client) WlanConfig(ctx context.Context) (XMLData, error)

WlanConfig retrieves basic WLAN settings.

func (*Client) WlanMonthInfo

func (cl *Client) WlanMonthInfo(ctx context.Context) (XMLData, error)

WlanMonthInfo retrieves the WLAN month download statistic information.

type ClientOption

type ClientOption func(*Client)

CLientOption is a client option.

func WithAuth

func WithAuth(id, pw string) ClientOption

WithAuth is a client option specifying the identifier and password to use. The option is ignored if id is an empty string.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient is a client option that sets the underlying http client.

func WithLogf

func WithLogf(logf func(string, ...interface{})) ClientOption

WithLogf is a client option that writes all http request and response data to the specified log func.

func WithNoStart

func WithNoStart(nostart bool) ClientOption

WithNoStart is a client option to disable automatic start.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout is a client option that sets the request timeout.

func WithTransport

func WithTransport(transport http.RoundTripper) ClientOption

WithTransport is a client option that sets the http transport used.

func WithURL

func WithURL(endpoint string) ClientOption

WithURL is a client option to set the URL endpoint.

type Error

type Error string

Error is the error type.

const (
	// ErrBadStatusCode is the bad status code error.
	ErrBadStatusCode Error = "bad status code"
	// ErrInvalidResponse is the invalid response error.
	ErrInvalidResponse Error = "invalid response"
	// ErrInvalidError is the invalid error error.
	ErrInvalidError Error = "invalid error"
	// ErrInvalidValue is the invalid value error.
	ErrInvalidValue Error = "invalid value"
	// ErrInvalidXML is the invalid xml error.
	ErrInvalidXML Error = "invalid xml"
	// ErrMissingRootElement is the missing root element error.
	ErrMissingRootElement Error = "missing root element"
	// ErrMessageTooLong is the message too long error.
	ErrMessageTooLong Error = "message too long"
)

Error values.

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type PinType

type PinType int

PinType are the PIN types for a PIN command.

const (
	PinTypeEnter PinType = iota
	PinTypeActivate
	PinTypeDeactivate
	PinTypeChange
	PinTypeEnterPuk
)

PinType values.

type SmsBoxType

type SmsBoxType uint

SmsBoxType represents the different inbox types available on a hilink device.

const (
	SmsBoxTypeInbox SmsBoxType = iota + 1
	SmsBoxTypeOutbox
	SmsBoxTypeDraft
)

SmsBoxType values.

type UssdState

type UssdState int

UssdState represents the different USSD states.

const (
	UssdStateNone UssdState = iota
	UssdStateActive
	UssdStateWaiting
)

UssdState values.

type XMLData

type XMLData mxj.Map

XMLData is a map of XML data to encode/decode.

Directories

Path Synopsis
cmd
sms

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL