This file is indexed.

/usr/lib/python2.7/dist-packages/framework/subsystems/ogsmd/server.py is in fso-frameworkd 0.10.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python
"""
The Open GSM Daemon - Python Implementation

(C) 2008 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
(C) 2008 Openmoko, Inc.
GPLv2 or later

Package: ogsmd
Module: server
"""

MODULE_NAME = "ogsmd.server"
__version__ = "0.2.0"

from framework import resource
from framework.patterns import tasklet
from gsm import const, celldb

import dbus
import dbus.service
from dbus import DBusException

import math
import sys, os
import types

import logging
logger = logging.getLogger( MODULE_NAME )

from device import DBUS_INTERFACE_DEVICE, \
                   DBUS_OBJECT_PATH_DEVICE, \
                   DBUS_BUS_NAME_DEVICE, \
                   DBUS_INTERFACE_SIM, \
                   DBUS_INTERFACE_NETWORK, \
                   DBUS_INTERFACE_PDP, \
                   DBUS_INTERFACE_CB

DBUS_INTERFACE_DATA = "org.freesmartphone.GSM.Data"
DBUS_INTERFACE_HZ = "org.freesmartphone.GSM.HZ"
DBUS_INTERFACE_PHONE = "org.freesmartphone.GSM.Phone"
DBUS_OBJECT_PATH_SERVER = "/org/freesmartphone/GSM/Server"

HOMEZONE_DEBUG = False

#=========================================================================#
class Server( dbus.service.Object ):
#=========================================================================#
    """
    Open Phone Server aggregated functions:
    - HomeZone

    Ideas:
    - watch for clients on bus and send coldplug status
    - monitor device aliveness and restart, if necessary
    """

    def __init__( self, bus ):
        self.path = DBUS_OBJECT_PATH_SERVER
        dbus.service.Object.__init__( self, bus, self.path )
        logger.info( "%s %s initialized." % ( self.__class__.__name__, __version__ ) )
        self.bus = bus
        self.homezones = None
        self.zone = "unknown"
        self.setupSignals()
        self._autoRegister = False
        self._service = "unknown"
        self._autoOnline = False
        self._online = "unknown"
        self.pin = None
        self.user = None
        self.password = None

    def setupSignals( self ):
        device = self.bus.get_object( DBUS_BUS_NAME_DEVICE, DBUS_OBJECT_PATH_DEVICE )
        self.fso_cb = dbus.Interface( device, DBUS_INTERFACE_CB )
        self.fso_cb.connect_to_signal( "IncomingCellBroadcast", self.onIncomingCellBroadcast )
        self.fso_sim = dbus.Interface( device, DBUS_INTERFACE_SIM )
        self.fso_network = dbus.Interface( device, DBUS_INTERFACE_NETWORK )
        self.fso_network.connect_to_signal( "Status", self.onIncomingGsmNetworkStatus )
        self.fso_pdp = dbus.Interface( device, DBUS_INTERFACE_PDP )
        self.fso_pdp.connect_to_signal( "ContextStatus", self.onIncomingGsmContextStatus )
        self.fso_device = dbus.Interface( device, DBUS_INTERFACE_DEVICE )

    def __del__( self ):
        server = None

    #
    # Callbacks
    #
    def onIncomingCellBroadcast( self, channel, data ):

        def gotHomezones( homezones, self=self ):
            logger.info( "got SIM homezones: %s", homezones )
            self.homezones = homezones
            # debug code, if you have no homezones on your SIM. To test, use:
            # gsm.DebugInjectString("UNSOL","+CBM: 16,221,0,1,1\r\n347747555093\r\r\r\n")
            if HOMEZONE_DEBUG: self.homezones = [ ( "city", 347747, 555093, 1000 ), ( "home", 400000, 500000, 1000 ) ]
            self.checkInHomezones()

        if channel == 221: # home zone cell broadcast
            if len( data ) != 12:
                return
            self.x, self.y = int( data[:6] ), int( data[6:] )
            logger.info( "home zone cell broadcast detected: %s %s", self.x, self.y )
            if self.homezones is None: # never tried to read them
                logger.info( "trying to read home zones from SIM" )
                self.fso_sim.GetHomeZones( reply_handler=gotHomezones, error_handler=lambda error:None )
            else:
                self.checkInHomezones()

    def checkInHomezones( self ):
        status = ""
        for zname, zx, zy, zr in self.homezones:
            if self.checkInHomezone( self.x, self.y, zx, zy, zr ):
                status = zname
                break
        self.HomeZoneStatus( status )

    def checkInHomezone( self, x, y, zx, zy, zr ):
        logger.info( "matching whether %s %s is in ( %s, %s, %s )" % ( x, y, zx, zy, zr ) )
        dist = math.sqrt( math.pow( x-zx, 2 ) + math.pow( y-zy, 2 ) ) * 10
        maxdist = math.sqrt( zr ) * 10
        return dist < maxdist

    def onIncomingGsmNetworkStatus( self, status ):
        reg = status["registration"]
        if reg in "home roaming".split():
            self._updateServiceStatus( "online" )
        else:
            self._updateServiceStatus( "offline" )
        if reg in "unregistered denied".split() and self._autoRegister:
            self.Register( self.pin, lambda:None, lambda Foo:None )

    def _updateServiceStatus( self, status ):
        if self._service != status:
            self._service = status
            self.ServiceStatus( status )

    def replyGetContextStatus( self, status ):
        self.onIncomingGsmContextStatus( 0, status, {} )

    def onIncomingGsmContextStatus( self, index, status, properties ):
        online = status
        if online == "active":
            self._updateOnlineStatus( "online" )
        else:
            self._updateOnlineStatus( "offline" )
        if online in "release".split() and self._autoOnline:
            self.GoOnline( self.apn, self.user, self.password, lambda:None, lambda Foo:None )

    def _updateOnlineStatus( self, status ):
        if self._online != status:
            self._online = status
            self.OnlineStatus( status )

    #
    # dbus org.freesmartphone.GSM.Data
    #
    @dbus.service.method( DBUS_INTERFACE_DATA, "ss", "a{sv}" )
    def GetNetworkInfo( self, mcc, mnc ):
        return const.NETWORKS.get( ( int(mcc), int(mnc) ), {} )

    # FIXME Return NaN when no cell found? Support signal strengths?
    @dbus.service.method( DBUS_INTERFACE_DATA, "ssa(uu)", "bddddu" )
    def GetCellLocation( self, mcc, mnc, cells ):
        mcc = int( mcc )
        mnc = int( mnc )
        cells = [map(int, cell) for cell in cells]
        center = celldb.get_center( mcc, mnc, cells )
        if center:
            return ( True, ) +center
        la = celldb.get_la( mcc, mnc, cells[0][0] )
        if la:
            return ( True, ) + la + ( 0, )
        return ( False, 0.0, 0.0, 0.0, 0.0, 0 )

    #
    # dbus org.freesmartphone.GSM.HZ
    #
    @dbus.service.method( DBUS_INTERFACE_HZ, "", "s",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def GetHomeZoneStatus( self, dbus_ok, dbus_error ):
        dbus_ok( self.zone )

    @dbus.service.signal( DBUS_INTERFACE_HZ, "s" )
    def HomeZoneStatus( self, zone ):
        self.zone = zone
        logger.info( "home zone status now %s" % zone )

    @dbus.service.method( DBUS_INTERFACE_HZ, "", "as",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def GetKnownHomeZones( self, dbus_ok, dbus_error ):

        def gotHomezones( homezones, self=self, dbus_ok=dbus_ok ):
            logger.info( "got SIM homezones: %s", homezones )
            self.homezones = homezones
            # debug code, if you have no homezones on your SIM. To test, use:
            # gsm.DebugInjectString("UNSOL","+CBM: 16,221,0,1,1\r\n347747555093\r\r\r\n")
            if HOMEZONE_DEBUG: self.homezones = [ ( "city", 347747, 555093, 1000 ), ( "home", 400000, 500000, 1000 ) ]
            dbus_ok( [ zone[0] for zone in self.homezones ] )

        self.fso_sim.GetHomeZones( reply_handler=gotHomezones, error_handler=lambda error:None )

    #
    # dbus org.freesmartphone.GSM.Phone (auto register)
    #
    @dbus.service.method( DBUS_INTERFACE_PHONE, "s", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def StartAutoRegister( self, pin, dbus_ok, dbus_error ):
        self.pin = pin
        self._autoRegister = True
        dbus_ok()
        self.fso_network.GetStatus( reply_handler=self.onIncomingGsmNetworkStatus, error_handler=lambda Foo:None )

    @dbus.service.method( DBUS_INTERFACE_PHONE, "", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def StopAutoRegister( self, dbus_ok, dbus_error ):
        self._autoRegister = False
        dbus_ok()

    @dbus.service.method( DBUS_INTERFACE_PHONE, "s", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def Register( self, pin, dbus_ok, dbus_error ):

        @tasklet.tasklet
        def worker( self, pin ):
            try:
                yield tasklet.WaitDBus( self.fso_device.SetAntennaPower, True )
            except dbus.DBusException, e: # may be locked
                if e.get_dbus_name() != "org.freesmartphone.GSM.SIM.AuthFailed":
                    raise
                else:
                    yield tasklet.WaitDBus( self.fso_sim.SendAuthCode, pin )

            yield tasklet.WaitDBus( self.fso_network.Register )
        worker( self, pin ).start_dbus( dbus_ok, dbus_error )

    @dbus.service.signal( DBUS_INTERFACE_PHONE, "s" )
    def ServiceStatus( self, service ):
       logger.info( "service status now %s" % service )

    #
    # dbus org.freesmartphone.GSM.Phone (auto online)
    #
    @dbus.service.method( DBUS_INTERFACE_PHONE, "sss", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def StartAutoOnline( self, apn, user, password, dbus_ok, dbus_error ):
        self.apn = apn
        self.user = user
        self.password = password
        self._autoOnline = True
        dbus_ok()
        self.fso_pdp.GetContextStatus( reply_handler=self.replyGetContextStatus, error_handler=lambda Foo:None )

    @dbus.service.method( DBUS_INTERFACE_PHONE, "", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def StopAutoOnline( self, dbus_ok, dbus_error ):
        self._autoOnline = False
        dbus_ok()

    @dbus.service.method( DBUS_INTERFACE_PHONE, "sss", "",
                          async_callbacks=( "dbus_ok", "dbus_error" ) )
    def GoOnline( self, apn, user, password, dbus_ok, dbus_error ):
        self.fso_pdp.ActivateContext( apn, user, password, reply_handler=dbus_ok, error_handler=dbus_error )

    @dbus.service.signal( DBUS_INTERFACE_PHONE, "s" )
    def OnlineStatus( self, online ):
       logger.info( "online status now %s" % online )


#=========================================================================#
def factory( prefix, controller ):
#=========================================================================#
    return [ Server( controller.bus ) ]

#=========================================================================#
if __name__ == "__main__":
#=========================================================================#
    pass