Ejemplo n.º 1
0
class Customizer(object):
    """
    I contain all the custom classes and metadata that a device needs
    
    @cvar adapter: Adapter for the device
    @type adapter: L{SIMCardConnAdapter} child.
    @cvar async_regexp: regexp to parse asynchronous notifications emited
    by the device.
    @cvar conn_dict: Dictionary with the AT strings necessary to change
    between the different connection modes
    @cvar cmd_dict: Dictionary with commands info
    @cvar device_capabilities: List with the unsolicited notifications that
    this device supports
    @cvar authklass: Class that will handle the authentication for this device
    @cvar connklass: Class that will handle the connection for this device
    @cvar netrklass: Class that will handle the network registration for this
    device
    """
    adapter = SIMCardConnAdapter
    async_regexp = None
    ignore_regexp = None
    conn_dict = {}
    cmd_dict = get_cmd_dict_copy()
    device_capabilities = []
    signal_translations = {}
    authklass = AuthStateMachine
    connklass = ConnectStateMachine
    netrklass = NetworkRegStateMachine
Ejemplo n.º 2
0
__version__ = "$Rev: 1209 $"

import re

from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer

ZTE_DICT = {
   'GPRSONLY' : 'AT^ZSNT=1,0,0',
   '3GONLY'   : 'AT^ZSNT=2,0,0',
   'GPRSPREF' : 'AT^ZSNT=0,0,1',
   '3GPREF'   : 'AT^ZSNT=1,0,2',
}


ZTE_CMD_DICT = get_cmd_dict_copy()

info = dict(echo=None,
            end=OK_REGEXP,
            error=ERROR_REGEXP,
            extract=re.compile(r"""
                \r\n
                \+CREG:\s
                (?P<mode>\d),(?P<status>\d+)(,[0-9a-fA-F]*,[0-9a-fA-F]*)?
                \r\n
                """, re.VERBOSE))

ZTE_CMD_DICT['get_netreg_status'] = info

class ZTECustomizer(Customizer):
    async_regexp = None
Ejemplo n.º 3
0
from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer

SIERRAWIRELESS_DICT = {
    '3GONLY': 'AT!SELRAT=01',
    '3GPREF': 'AT!SELRAT=03',
    'GPRSONLY': 'AT!SELRAT=02',
    'GPRSPREF': 'AT!SELRAT=04',
}

# Sierra devices like to append garbage after CREG like:
# [-] SIMCardConnAdapter: SENDING ATCMD 'AT+CREG?\r\n'
# [-] SIMCardConnAdapter: NEW STATE: waiting
# [-] SIMCardConnAdapter: DATA_RCV: '\r\n+CREG: 0,1,03F3,2993\r\n\r\nOK\r\n'
SIERRA_CMD_DICT = get_cmd_dict_copy()

info = dict(echo=None,
            end=OK_REGEXP,
            error=ERROR_REGEXP,
            extract=re.compile(
                r"""
                \r\n
                \+CREG:\s
                (?P<mode>\d),(?P<status>\d+)(,[0-9a-fA-F]*,[0-9a-fA-F]*)?
                \r\n
                """, re.VERBOSE))

SIERRA_CMD_DICT['get_netreg_status'] = info

Ejemplo n.º 4
0
class EricssonCustomizer(Customizer):
    """
    Base Customizer class for Ericsson cards
    """

    adapter = EricssonAdapter

    # Multiline so we catch and remove the ESTKSMENU
    #    async_regexp = re.compile(r"""\r\n(?P<signal>\*[A-Z]{3,}):(?P<args>.*)\r\n""",
    #                        re.MULTILINE)

    ignore_regexp = [
        re.compile(r"""\r\n(?P<ignore>\*ESTKSMENU:.*)\r\n""",
                   re.MULTILINE | re.DOTALL),
        re.compile(r"""\r\n(?P<ignore>\*EMWI.*)\r\n"""),
        re.compile(r"""\r\n(?P<ignore>\+PACSP0.*)\r\n"""),
    ]

    conn_dict = ERICSSON_DICT

    cmd_dict = get_cmd_dict_copy()

    cmd_dict['get_card_model'] = dict(
        echo=None,
        end=OK_REGEXP,
        error=ERROR_REGEXP,
        extract=re.compile('\s*(?P<model>\S*)\r\n'))

    # +CIND: 5,5,0,0,1,0,1,0,1,1,0,0
    cmd_dict['get_signal_indication'] = dict(
        echo=None,
        end=OK_REGEXP,
        error=ERROR_REGEXP,
        extract=re.compile('\s*\+CIND:\s+[0-9]*,(?P<sig>[0-9]*),.*'))

    cmd_dict['get_network_info'] = dict(echo=None,
                                        end=OK_REGEXP,
                                        error=ERROR_REGEXP,
                                        extract=re.compile(
                                            r"""
                          \r\n
                          \+COPS:\s+
                          (
                          (?P<error>\d) |
                          \d,\d,             # or followed by num,num,str,num
                          "(?P<netname>[\w\S ]*)",
                          (?P<status>\d)
                          )                  # end of group
                          \s*
                          \r\n
                          """, re.VERBOSE))

    # +CPBR: 1,"002B003500350035",145,"0041004A0042"\r\n'
    cmd_dict['get_contacts'] = dict(echo=None,
                                    end=re.compile('(\r\n)?\r\n(OK)\r\n'),
                                    error=ERROR_REGEXP,
                                    extract=re.compile(
                                        r"""
                       \r\n
                       \+CPBR:\s(?P<id>\d+),
                       "(?P<number>\+?[0123456789ABCDEFabcdef]+)",
                       (?P<cat>\d+),
                       "(?P<name>.*)"
                       """, re.VERBOSE))

    # +CPBR: (1-200),80,14,20,80,128
    cmd_dict['get_phonebook_size'] = dict(echo=None,
                                          end=OK_REGEXP,
                                          error=ERROR_REGEXP,
                                          extract=re.compile(
                                              r"""
                    \r\n
                    \+CPBR:\s
                    \(\d\-(?P<size>\d+)\)
                    (?P<ignored>,.*)?
                    \r\n
                    """, re.VERBOSE))
# 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.

__version__ = "$Rev: 1209 $"

from vmc.common.exceptions import DeviceLacksExtractInfo
from vmc.common.hardware.zte import ZTECustomizer, ZTEDBusDevicePlugin

import re

from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer


ZTE2525_CMD_DICT = get_cmd_dict_copy()

ZTE2525_CMD_DICT['get_netreg_status'] = dict(echo=None,
                end=OK_REGEXP,
                error=ERROR_REGEXP,
                extract=re.compile(r"""
                \r\n
                \+CREG:\s
                (?P<mode>\d),(?P<status>\d+)(,[0-9a-fA-F]*,[0-9a-fA-F]*)?
                \r\n
                """, re.VERBOSE))

ZTE2525_CMD_DICT['get_network_info'] = dict(echo=None,
                end=OK_REGEXP,
                error=ERROR_REGEXP,
                extract=re.compile(r"""
Ejemplo n.º 6
0
from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer
from vmc.common.sim import SIMBaseClass
from vmc.common.plugin import DBusDevicePlugin
import vmc.common.notifications as N

OPTION_DICT = {
   'GPRSONLY' : 'AT_OPSYS=0,2',
   '3GONLY'   : 'AT_OPSYS=1,2',
   'GPRSPREF' : 'AT_OPSYS=2,2',
   '3GPREF'   : 'AT_OPSYS=3,2',
}


# Option devices like to append its serial number after the IMEI, ignore it
OPTION_CMD_DICT = get_cmd_dict_copy()
info = dict(echo=None,
            end=OK_REGEXP,
            error=ERROR_REGEXP,
            extract=re.compile("\r\n(?P<imei>\d+),\S+\r\n"))

OPTION_CMD_DICT['get_imei'] = info

class OptionSIMClass(SIMBaseClass):
    """
    Nozomi SIM Class
    
    I just activate unsolicited notifications for ya
    """
    def __init__(self, sconn):
        super(OptionSIMClass, self).__init__(sconn)
Ejemplo n.º 7
0
#
# 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.

__version__ = "$Rev: 1209 $"

from vmc.common.exceptions import DeviceLacksExtractInfo
from vmc.common.hardware.zte import ZTECustomizer, ZTEDBusDevicePlugin

import re

from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer

ZTE2525_CMD_DICT = get_cmd_dict_copy()

ZTE2525_CMD_DICT['get_netreg_status'] = dict(echo=None,
                                             end=OK_REGEXP,
                                             error=ERROR_REGEXP,
                                             extract=re.compile(
                                                 r"""
                \r\n
                \+CREG:\s
                (?P<mode>\d),(?P<status>\d+)(,[0-9a-fA-F]*,[0-9a-fA-F]*)?
                \r\n
                """, re.VERBOSE))

ZTE2525_CMD_DICT['get_network_info'] = dict(echo=None,
                                            end=OK_REGEXP,
                                            error=ERROR_REGEXP,
Ejemplo n.º 8
0
import re

from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer
from vmc.common.sim import SIMBaseClass
from vmc.common.plugin import DBusDevicePlugin

ICERA_DICT = {
   'GPRSONLY': 'AT%IPSYS=0',
   '3GONLY': 'AT%IPSYS=1',
   'GPRSPREF': 'AT%IPSYS=2',
   '3GPREF': 'AT%IPSYS=3',
}

ICERA_CMD_DICT = get_cmd_dict_copy()

# \r\n+CPBR: (1-200),80,14,0,0,0\r\n\r\nOK\r\n'
ICERA_CMD_DICT['get_phonebook_size'] = dict(
    echo=None,
    end=OK_REGEXP,
    error=ERROR_REGEXP,
    extract=re.compile(r"""
        \r\n
        \+CPBR:\s
        \(\d+-(?P<size>\d+)\).*
        \r\n
    """, re.VERBOSE))

# \r\n
# +CMGL: 1,1,"616E64726577",23\r\n0791447758100650040C914497716247010
Ejemplo n.º 9
0
__version__ = "$Rev: 1209 $"

import re

from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer

ZTE_DICT = {
    'GPRSONLY': 'AT^ZSNT=1,0,0',
    '3GONLY': 'AT^ZSNT=2,0,0',
    'GPRSPREF': 'AT^ZSNT=0,0,1',
    '3GPREF': 'AT^ZSNT=1,0,2',
}

ZTE_CMD_DICT = get_cmd_dict_copy()

info = dict(echo=None,
            end=OK_REGEXP,
            error=ERROR_REGEXP,
            extract=re.compile(
                r"""
                \r\n
                \+CREG:\s
                (?P<mode>\d),(?P<status>\d+)(,[0-9a-fA-F]*,[0-9a-fA-F]*)?
                \r\n
                """, re.VERBOSE))

ZTE_CMD_DICT['get_netreg_status'] = info

# 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.
"""Unittests for the command module"""

__version__ = "$Rev: 1172 $"

import re
from twisted.trial import unittest

from vmc.common.command import get_cmd_dict_copy

cmd_dict = get_cmd_dict_copy()

class TestCommandsRegexps(unittest.TestCase):
    """Test for csvutils functionality"""
    
    def test_check_pin_regexp(self):
        # [-] SENDING ATCMD 'AT+CPIN?\r\n'
        # [-] WAITING: DATA_RCV = '\r\n+CPIN: READY\r\n\r\nOK\r\n'
        extract = cmd_dict['check_pin']['extract']
        text = '\r\n+CPIN: READY\r\n\r\nOK\r\n'
        match = extract.match(text)
        self.failIf(match == None)
        self.assertEqual(match.group('resp'), 'READY')
        # [-] WAITING: DATA_RCV = '\r\n+CPIN: SIM PIN\r\n\r\nOK\r\n'
        text2 = '\r\n+CPIN: SIM PIN\r\n\r\nOK\r\n'
        match = extract.match(text2)
Ejemplo n.º 11
0
class HuaweiCustomizer(Customizer):
    """
    Base Customizer class for Huawei cards
    """
    adapter = HuaweiAdapter

    async_regexp = re.compile(
        '\r\n(?P<signal>\^MODE|\^RSSI|\^DSFLOWRPT|\^RFSWITCH):(?P<args>.*)\r\n'
    )
    ignore_regexp = [
        re.compile('\r\n(?P<ignore>\^BOOT:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^CSNR:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^EARST:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^SRVST:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^SIMST:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^STIN:.*)\r\n'),
        re.compile('\r\n(?P<ignore>\^SMMEMFULL:.*)\r\n'),
    ]
    conn_dict = HUAWEI_DICT
    device_capabilities = [
        notifications.SIG_NEW_CONN_MODE, notifications.SIG_RSSI,
        notifications.SIG_SPEED, notifications.SIG_RFSWITCH
    ]

    cmd_dict = get_cmd_dict_copy()

    cmd_dict['get_card_model'] = dict(
        echo=None,
        end=OK_REGEXP,
        error=ERROR_REGEXP,
        extract=re.compile('\s*(?P<model>\S*)\r\n'))

    cmd_dict['get_radio'] = dict(
        echo=None,
        end=OK_REGEXP,
        error=ERROR_REGEXP,
        extract=re.compile('\s*\^RFSWITCH:(?P<switch>\S*)\r\n'))

    cmd_dict['get_contact_by_index'] = dict(echo=None,
                                            end=re.compile('\r\nOK\r\n'),
                                            error=ERROR_REGEXP,
                                            extract=re.compile(
                                                r"""
                       \r\n
                       \^CPBR:\s(?P<id>\d+),
                       "(?P<number>\+?\d+)",
                       (?P<cat>\d+),
                       "(?P<name>.*)",
                       (?P<raw>\d+)
                       \r\n
                       """, re.VERBOSE))

    cmd_dict['get_contacts'] = dict(
        echo=None,
        # one extra \r\n just in case
        end=re.compile('(\r\n)?\r\n(OK)\r\n'),
        error=ERROR_REGEXP,
        extract=re.compile(
            r"""
                       \r\n
                       \^CPBR:\s(?P<id>\d+),
                       "(?P<number>\+?\d+)",
                       (?P<cat>\d+),
                       "(?P<name>.*)",
                       (?P<raw>\d+)
                       """, re.VERBOSE))

    signal_translations = {
        '^MODE': (notifications.SIG_NEW_CONN_MODE, huawei_new_conn_mode),
        '^RSSI': (notifications.SIG_RSSI, lambda i: int(i)),
        '^DSFLOWRPT': (notifications.SIG_SPEED, huawei_new_speed_link),
        '^RFSWITCH': (notifications.SIG_RFSWITCH, huawei_radio_switch),
    }
Ejemplo n.º 12
0
from vmc.common.command import get_cmd_dict_copy, OK_REGEXP, ERROR_REGEXP
from vmc.common.hardware.base import Customizer
from vmc.common.sim import SIMBaseClass
from vmc.common.plugin import DBusDevicePlugin
import vmc.common.notifications as N

OPTION_DICT = {
    'GPRSONLY': 'AT_OPSYS=0,2',
    '3GONLY': 'AT_OPSYS=1,2',
    'GPRSPREF': 'AT_OPSYS=2,2',
    '3GPREF': 'AT_OPSYS=3,2',
}

# Option devices like to append its serial number after the IMEI, ignore it
OPTION_CMD_DICT = get_cmd_dict_copy()
info = dict(echo=None,
            end=OK_REGEXP,
            error=ERROR_REGEXP,
            extract=re.compile("\r\n(?P<imei>\d+),\S+\r\n"))

OPTION_CMD_DICT['get_imei'] = info


class OptionSIMClass(SIMBaseClass):
    """
    Nozomi SIM Class
    
    I just activate unsolicited notifications for ya
    """
    def __init__(self, sconn):
Ejemplo n.º 13
0
# 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.
"""Unittests for the command module"""

__version__ = "$Rev: 1172 $"

import re
from twisted.trial import unittest

from vmc.common.command import get_cmd_dict_copy

cmd_dict = get_cmd_dict_copy()


class TestCommandsRegexps(unittest.TestCase):
    """Test for csvutils functionality"""
    def test_check_pin_regexp(self):
        # [-] SENDING ATCMD 'AT+CPIN?\r\n'
        # [-] WAITING: DATA_RCV = '\r\n+CPIN: READY\r\n\r\nOK\r\n'
        extract = cmd_dict['check_pin']['extract']
        text = '\r\n+CPIN: READY\r\n\r\nOK\r\n'
        match = extract.match(text)
        self.failIf(match == None)
        self.assertEqual(match.group('resp'), 'READY')
        # [-] WAITING: DATA_RCV = '\r\n+CPIN: SIM PIN\r\n\r\nOK\r\n'
        text2 = '\r\n+CPIN: SIM PIN\r\n\r\nOK\r\n'
        match = extract.match(text2)