예제 #1
0
    def start(self, options, args):
        bb_messenging.verbose = True
        # Need to be root (unless udev or OSX)
        if os.getuid() != 0:
            bb_messenging.log(
                "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nThis might will only work as root!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
            )

        bb_util.remove_berry_charge()
        bb_osx.prepare_osx()
        berry = None
        berry = bb_usb.find_berry(None, None)

        if berry != None:
            # open the connection
            if berry.handle == None:
                berry.open_handle()

            berry.read_endpoints(None)

            bb_util.remove_berry_charge()

            if berry.readpt == -1:
                bb_messenging.warn(
                    ["\nNo good Data Endpoint pair, bailing out !"])
            else:
                bb_messenging.log("\nUsing Data Endpoint Pair:" +
                                  hex(berry.readpt) + "/" + hex(berry.writept))
                bb_messenging.log("Using Modem pair: " +
                                  hex(berry.modem_readpt) + "/" +
                                  hex(berry.modem_writept) + "\n")

                bb_messenging.log("Claiming interface " + str(berry.interface))
                berry.claim_interface()

                berry.read_infos()
                bb_messenging.log("Pin: " + hex(berry.pin))
                bb_messenging.log("Description: " + berry.desc)

                bb_usb.set_mode(berry, bb_usb.COMMAND_MODE_DESKTOP)
                bb_usb.usb_read(berry, berry.readpt)
                bb_usb.usb_write(berry, berry.writept,
                                 [00, 00, 0x7, 00, 0xa, 04, 00])
                bb_usb.usb_read(berry, berry.readpt)
                bb_usb.usb_write(
                    berry, berry.writept,
                    [04, 00, 0xc, 00, 0x40, 00, 00, 00, 0x25, 0x80, 0x8, 00])
                bb_usb.usb_read(berry, berry.readpt)
                time.sleep(2)
                bb_usb.usb_read(berry, berry.readpt)

        else:
            bb_messenging.warn(["\nNo RIM device found"])
예제 #2
0
def prepare_osx():
	if is_supported_osx():
		if os.getuid() == 0:
			# Note: pocketmac kext preventing us from working !:
			if os.path.isdir("/System/Library/Extensions/net.pocketmac.driver.BlackberryUSB.kext"):
				msgs=["PocketMac found, it's incompatible with bbtether, will try to disbale it temporarily",
				"*** Note that this might not work, you might have to uninstall pocketMac :-( **"]
				bb_messenging.warn(msgs)
				bb_messenging.confirm(["Please Unplug the Blackberry"])
				unload_pocketmac()
				bb_messenging.confirm(["Please Plug the Blackberry"])
            #if not os.path.isdir("/System/Library/Extensions/libusbshield_rim.kext/"):
			#	raw_input("Please Unplug the Blackberry, then press Enter")
			#	install_kextd()
			#	raw_input("Please Plug the Blackberry, then press Enter")
		else:
			if os.path.isdir("/System/Library/Extensions/net.pocketmac.driver.BlackberryUSB.kext"):
				bb_messenging.warn(["Need to run as root(sudo) to disable net.pocketmac.driver.BlackberryUSB.kext"])
				os._exit(0)
			#if not os.path.isdir("/System/Library/Extensions/libusbshield_rim.kext/"):
			#	print "Need to run as root(sudo) to install libusbshield_rim.kext (just once)"
			#	os._exit(0)
			if not os.path.isfile(SECRETS_FILE):
				bb_messenging.warn(["Need to run as root(sudo) to install " + SECRETS_FILE + " (just once)"])
				os._exit(0)


        # won't manage to do pap without this
		if not os.path.isfile(SECRETS_FILE):
			bb_messenging.warn(["the file " + SECRETS_FILE + " does not exist, will try to create it(required)"])
			file = open(SECRETS_FILE, 'w')
			file.write("*	*	\"\"	*")
			file.close()
			os.chown(SECRETS_FILE, 0, 0)#root:wheel
			os.chmod(SECRETS_FILE, 600)#might contain passwords .. some day
예제 #3
0
	def start(self, options, args):
		bb_messenging.verbose = True
		# Need to be root (unless udev or OSX)
		if os.getuid() != 0:
			bb_messenging.log("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nThis might will only work as root!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")

		bb_util.remove_berry_charge()
		bb_osx.prepare_osx()
		berry = None
		berry = bb_usb.find_berry(None,None)

		if berry != None:
			# open the connection
			if berry.handle==None:
				berry.open_handle()

			berry.read_endpoints(None)

			bb_util.remove_berry_charge()

			if berry.readpt == -1:
				bb_messenging.warn(["\nNo good Data Endpoint pair, bailing out !"])
			else:
				bb_messenging.log("\nUsing Data Endpoint Pair:"+ hex(berry.readpt)+ "/"+ hex(berry.writept))
				bb_messenging.log("Using Modem pair: "+ hex(berry.modem_readpt)+ "/"+ hex(berry.modem_writept)+ "\n")
				
				bb_messenging.log("Claiming interface "+str(berry.interface))
				berry.claim_interface()

				berry.read_infos()
				bb_messenging.log("Pin: "+ hex(berry.pin))
				bb_messenging.log("Description: "+ berry.desc)

				bb_usb.set_mode(berry,bb_usb.COMMAND_MODE_DESKTOP)
				bb_usb.usb_read(berry,berry.readpt)
				bb_usb.usb_write(berry,berry.writept,[00,00,0x7,00,0xa,04,00])
				bb_usb.usb_read(berry,berry.readpt)
				bb_usb.usb_write(berry,berry.writept,[04,00,0xc,00,0x40,00,00,00,0x25,0x80,0x8,00])
				bb_usb.usb_read(berry,berry.readpt)
				time.sleep(2)
				bb_usb.usb_read(berry,berry.readpt)

		else:
			bb_messenging.warn(["\nNo RIM device found"])
예제 #4
0
def remove_berry_charge():
# Remove module berry_charge if present, cause it causes problems
	if (not bb_osx.is_osx()) and  module_loaded("berry_charge"):
		msg=[" * Module berry_charge is loaded, this might cause problems","\t -> Will try to unload it now"]
		bb_messenging.warn(msg)
		unload_module("berry_charge")
		if module_loaded("berry_charge"):
			msg=["************************************************************",
			"Could NOT unload module berry_charge ! (must be in use)",
			"You should probably blacklist it",
			"create a file as root called: /etc/modprobe.d/blackberry",
			"inside it write 'blacklist berry_charge' (without the quotes)",
			"save it, then unplug the blackberry",
			"run  \"sudo /etc/init.d/udev restart\"",
			"replug the blackberry and try again",
			"************************************************************\n"
			]
			bb_messenging.warn(msg)
		else:
			print "\t -> OK.\n"
예제 #5
0
파일: bb_osx.py 프로젝트: tcolar/berry4all
def prepare_osx():
    if is_supported_osx():
        if os.getuid() == 0:
            # Note: pocketmac kext preventing us from working !:
            if os.path.isdir(
                    "/System/Library/Extensions/net.pocketmac.driver.BlackberryUSB.kext"
            ):
                msgs = [
                    "PocketMac found, it's incompatible with bbtether, will try to disbale it temporarily",
                    "*** Note that this might not work, you might have to uninstall pocketMac :-( **"
                ]
                bb_messenging.warn(msgs)
                bb_messenging.confirm(["Please Unplug the Blackberry"])
                unload_pocketmac()
                bb_messenging.confirm(["Please Plug the Blackberry"])
            #if not os.path.isdir("/System/Library/Extensions/libusbshield_rim.kext/"):
            #    raw_input("Please Unplug the Blackberry, then press Enter")
            #    install_kextd()
            #    raw_input("Please Plug the Blackberry, then press Enter")
        else:
            if os.path.isdir(
                    "/System/Library/Extensions/net.pocketmac.driver.BlackberryUSB.kext"
            ):
                bb_messenging.warn([
                    "Need to run as root(sudo) to disable net.pocketmac.driver.BlackberryUSB.kext"
                ])
                os._exit(0)
            #if not os.path.isdir("/System/Library/Extensions/libusbshield_rim.kext/"):
            #    print "Need to run as root(sudo) to install libusbshield_rim.kext (just once)"
            #    os._exit(0)
            if not os.path.isfile(SECRETS_FILE):
                bb_messenging.warn([
                    "Need to run as root(sudo) to install " + SECRETS_FILE +
                    " (just once)"
                ])
                os._exit(0)

        # won't manage to do pap without this
        if not os.path.isfile(SECRETS_FILE):
            bb_messenging.warn([
                "the file " + SECRETS_FILE +
                " does not exist, will try to create it(required)"
            ])
            file = open(SECRETS_FILE, 'w')
            file.write("*    *    \"\"    *")
            file.close()
            os.chown(SECRETS_FILE, 0, 0)  #root:wheel
            os.chmod(SECRETS_FILE, 600)  #might contain passwords .. some day
예제 #6
0
파일: bb_util.py 프로젝트: tcolar/berry4all
def remove_berry_charge():
    # Remove module berry_charge if present, cause it causes problems
    if (not bb_osx.is_osx()) and module_loaded("berry_charge"):
        msg = [
            " * Module berry_charge is loaded, this might cause problems",
            "\t -> Will try to unload it now"
        ]
        bb_messenging.warn(msg)
        unload_module("berry_charge")
        if module_loaded("berry_charge"):
            msg = [
                "************************************************************",
                "Could NOT unload module berry_charge ! (must be in use)",
                "You should probably blacklist it",
                "create a file as root called: /etc/modprobe.d/blackberry",
                "inside it write 'blacklist berry_charge' (without the quotes)",
                "save it, then unplug the blackberry",
                "run  \"sudo /etc/init.d/udev restart\"",
                "replug the blackberry and try again",
                "************************************************************\n"
            ]
            bb_messenging.warn(msg)
        else:
            print "\t -> OK.\n"
예제 #7
0
	def start(self, options, args):
		


		bb_messenging.verbose = options.verbose
		bb_messenging.veryVerbose = options.veryverbose
		if(options.rescan):
			prefs=bb_prefs.get_prefs()
			prefs.remove_section(bb_prefs.SECTION_SCANNED_EP)
			

		pppConfig = None
		if len(args) > 0:
			pppConfig = args[0]

		# Need to be root (unless udev or OSX)
		#if os.getuid() != 0:
		#	bb_messenging.log("\n!!!!!!!!!!!!!!!!!!!!!\nThis might will only work as root!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")

		bb_util.remove_berry_charge()
		bb_osx.prepare_osx()

		berry = None
		
		berry = bb_usb.find_berry(options.device, options.bus)

		if berry != None:
			# open the connection
			if berry.handle==None:
				berry.open_handle()

			#bb_usbfs.find_kernel_driver(berry)

			# lookup endpoints
			# IMPORTANT: We need to do this BEFORE RESET, otherwise modem will be screwed
			# folowing "test" hello packet (fail on Pearl, ok on storm)
			# all right on the Bold the hello packet also causes problem, but reset won't fix it :-(
			if not (options.drp and options.dwp and options.mrp and options.mwp):
				berry.read_endpoints(options.interface)

			if options.listonly:
				bb_messenging.warn(["Fin."])
				bb_osx.terminate_osx()
				os._exit(0)

			bb_util.remove_berry_charge()

			# set power & reset (only if '-c' requested)
			# Only needed with BB os < 4.5 ?
			if options.charge:
				bb_usb.set_bb_power(berry)
				bb_messenging.status("Waiting few seconds, for mode to change")
				time.sleep(1.5)

			# set to datamode (ony if requested)
			if options.dmode:
				bb_usb.set_data_mode(berry)

			#if options.password != None and len(options.password) > 0:
			#	bb_usb.set_desktop_mode(berry,options.password)

			# overwrite found endpoints with user endpoints if specified
			if options.drp:
				berry.readpt = int(options.drp, 16)
			if options.dwp:
				berry.writept = int(options.dwp, 16)
			if options.mrp:
				berry.modem_readpt = int(options.mrp, 16)
			if options.mwp:
				berry.modem_writept = int(options.mwp, 16)
			if options.interface:
				berry.interface = int(options.interface)

			if berry.readpt == -1:
				bb_messenging.warn(["\nNo good Data Endpoint pair, bailing out !"])
			else:
				bb_messenging.log("\nUsing Data Endpoint Pair:"+ hex(berry.readpt)+ "/"+ hex(berry.writept))
				bb_messenging.log("Using Modem pair: "+ hex(berry.modem_readpt)+ "/"+ hex(berry.modem_writept)+ "\n")
				
				bb_messenging.log("Atachando la interface "+str(berry.interface))
				berry.claim_interface()

				berry.read_infos()
				bb_messenging.log("Pin: "+ hex(berry.pin))
				bb_messenging.log("Description: "+ berry.desc)

				# Modem use does not require to be in desktop mode, so don't do it.
				self.modem = bb_modem.BBModem(berry)
				
				if options.password:
					self.modem.set_password(options.password)
				
				pppdCommand = "/usr/sbin/pppd";
				if options.pppd:
					pppdCommand = options.pppd

				# El desktop manager de windows hace esto, pero parce que es innecesario ya que igual funciona
				# asi que no lo voy a incluir en el paquete de datos
				#bb_usb.usb_write(berry, berry.writept, bb_modem.MODEM_BYPASS_PCKT)
				#bb_usb.usb_read(berry, berry.readpt)
				#bb_usb.usb_write(berry, berry.writept, [0,0,0x8,0,0xa,0x6,0,0xa])
				#bb_usb.usb_read(berry, berry.readpt)
				#bb_usb.usb_write(berry, berry.writept, [0x6,0,0xa,0,0x40,0,0,0x1,0,0])
				#bb_usb.usb_read(berry, berry.readpt)
				#bb_usb.usb_write(berry, berry.writept,[0x6,0,0x16,0,0x40,0x1,0x1,0x2,0,0,0,0xa,0x49,0,0,0,0,0x49,0,0,0,0x1])
				#bb_usb.usb_read(berry, berry.readpt)
				
				# This will run forever (until ^C)
				try:
					self.modem.start(pppConfig, pppdCommand)
				except KeyboardInterrupt:
					bb_messenging.log("KBD interrupt")
					# sometimes the KInterrupt will propagate here(if ^C before modem read thread started)
					# we don't want to crash and hang.
					if self.modem!=None:
						self.modem.do_shutdown()

				bb_messenging.status("MSG:Liberando la interfaz")
				berry.release_interface()
				bb_osx.terminate_osx()
				bb_messenging.status("END:LinBerryModem Finalizado")
				#os._exit(0)
		else:
			bb_messenging.warn(["\nERR:No hay BlackBerry Conectado!"])
예제 #8
0
파일: bb_usb.py 프로젝트: tcolar/berry4all
    device.readpt=readpt
    device.writept=writept
    device.modem_readpt=modem_readpt
    device.modem_writept=modem_writept

    #save scan results to file (only if found)
    if writept!=-1:
        bb_messenging.log("***********************************************")
        msgs=["We just ran the initial device Endpoints Scan",
        "This needs to be done only once.",
        "Saved the scan results to "+PREF_FILE,
        "some devices (Bold) do not like being scanned.","",
        "AND WILL NEED THE BATTERY REMOVED / ADDED (just this once)",
        "BEFORE YOU CAN USE THE MODEM."]
        bb_messenging.warn(msgs)
        bb_messenging.log("***********************************************")
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP,'interface', device.interface)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP,'readpt', device.readpt)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP,'writept', device.writept)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP,'modem_readpt', device.modem_readpt)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP,'modem_writept', device.modem_writept)
        bb_messenging.log("Saving EP data: "+str(device.interface)+", "+str(device.readpt)+", "+str(device.writept)+", "+str(device.modem_readpt)+", "+str(device.modem_writept))
        bb_prefs.save_prefs()

def clear_halt(device, endpt):
    device.handle.clearHalt(endpt)

def set_bb_power(device):
    '''
    Added try / expect blocks as I had reports of failure(which ?) on storm 9500
예제 #9
0
    def start(self, options, args):
        bb_messenging.verbose = options.verbose
        bb_messenging.veryVerbose = options.veryverbose
        if (options.rescan):
            prefs = bb_prefs.get_prefs()
            prefs.remove_section(bb_prefs.SECTION_SCANNED_EP)

        pppConfig = None
        if len(args) > 0:
            pppConfig = args[0]

        # Need to be root (unless udev or OSX)
        if os.getuid() != 0:
            bb_messenging.log(
                "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nThis might will only work as root!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
            )

        bb_util.remove_berry_charge()
        bb_osx.prepare_osx()

        berry = None

        berry = bb_usb.find_berry(options.device, options.bus)

        if berry != None:
            # open the connection
            if berry.handle == None:
                berry.open_handle()

            #bb_usbfs.find_kernel_driver(berry)

            # lookup endpoints
            # IMPORTANT: We need to do this BEFORE RESET, otherwise modem will be screwed
            # folowing "test" hello packet (fail on Pearl, ok on storm)
            # all right on the Bold the hello packet also causes problem, but reset won't fix it :-(
            if not (options.drp and options.dwp and options.mrp
                    and options.mwp):
                berry.read_endpoints(options.interface)

            if options.listonly:
                bb_messenging.warn(["Listing only requested, stopping here."])
                bb_osx.terminate_osx()
                os._exit(0)

            bb_util.remove_berry_charge()

            # set power & reset (only if '-c' requested)
            # Only needed with BB os < 4.5 ?
            if options.charge:
                bb_usb.set_bb_power(berry)
                bb_messenging.status("Waiting few seconds, for mode to change")
                time.sleep(1.5)

            # set to datamode (ony if requested)
            if options.dmode:
                bb_usb.set_data_mode(berry)

            #if options.password != None and len(options.password) > 0:
            #    bb_usb.set_desktop_mode(berry,options.password)

            # overwrite found endpoints with user endpoints if specified
            if options.drp:
                berry.readpt = int(options.drp, 16)
            if options.dwp:
                berry.writept = int(options.dwp, 16)
            if options.mrp:
                berry.modem_readpt = int(options.mrp, 16)
            if options.mwp:
                berry.modem_writept = int(options.mwp, 16)
            if options.interface:
                berry.interface = int(options.interface)

            if berry.readpt == -1:
                bb_messenging.warn(
                    ["\nNo good Data Endpoint pair, bailing out !"])
            else:
                bb_messenging.log("\nUsing Data Endpoint Pair:" +
                                  hex(berry.readpt) + "/" + hex(berry.writept))
                bb_messenging.log("Using Modem pair: " +
                                  hex(berry.modem_readpt) + "/" +
                                  hex(berry.modem_writept) + "\n")

                bb_messenging.log("Claiming interface " + str(berry.interface))
                berry.claim_interface()

                berry.read_infos()
                bb_messenging.log("Pin: " + hex(berry.pin))
                bb_messenging.log("Description: " + berry.desc)

                # Modem use does not require to be in desktop mode, so don't do it.
                self.modem = bb_modem.BBModem(berry)

                if options.password:
                    self.modem.set_password(options.password)

                pppdCommand = "/usr/sbin/pppd"
                if options.pppd:
                    pppdCommand = options.pppd

                # Windows does this, however it does not seem to be required (seem to crash usb at times too)
                #bb_usb.usb_write(berry, berry.writept, bb_modem.MODEM_BYPASS_PCKT)
                #bb_usb.usb_read(berry, berry.readpt)
                #bb_usb.usb_write(berry, berry.writept, [0,0,0x8,0,0xa,0x6,0,0xa])
                #bb_usb.usb_read(berry, berry.readpt)
                #bb_usb.usb_write(berry, berry.writept, [0x6,0,0xa,0,0x40,0,0,0x1,0,0])
                #bb_usb.usb_read(berry, berry.readpt)
                #bb_usb.usb_write(berry, berry.writept, [0x6,0,0x16,0,0x40,0x1,0x1,0x2,0,0,0,0xa,0x49,0,0,0,0,0x49,0,0,0,0x1])
                #bb_usb.usb_read(berry, berry.readpt)

                # This will run forever (until ^C)
                try:
                    self.modem.start(pppConfig, pppdCommand)
                except KeyboardInterrupt:
                    bb_messenging.log("KBD interrupt")
                    # sometimes the KInterrupt will propagate here(if ^C before modem read thread started)
                    # we don't want to crash and hang.
                    if self.modem != None:
                        self.modem.do_shutdown()

                bb_messenging.status("Releasing interface")
                berry.release_interface()
                bb_osx.terminate_osx()
                bb_messenging.status("bbtether completed.")
                #os._exit(0)
        else:
            bb_messenging.warn(["\nNo RIM device found"])
예제 #10
0
파일: bb_usb.py 프로젝트: tcolar/berry4all
    device.writept = writept
    device.modem_readpt = modem_readpt
    device.modem_writept = modem_writept

    #save scan results to file (only if found)
    if writept != -1:
        bb_messenging.log("***********************************************")
        msgs = [
            "We just ran the initial device Endpoints Scan",
            "This needs to be done only once.",
            "Saved the scan results to " + PREF_FILE,
            "some devices (Bold) do not like being scanned.", "",
            "AND WILL NEED THE BATTERY REMOVED / ADDED (just this once)",
            "BEFORE YOU CAN USE THE MODEM."
        ]
        bb_messenging.warn(msgs)
        bb_messenging.log("***********************************************")
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP, 'interface',
                     device.interface)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP, 'readpt', device.readpt)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP, 'writept', device.writept)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP, 'modem_readpt',
                     device.modem_readpt)
        bb_prefs.set(bb_prefs.SECTION_SCANNED_EP, 'modem_writept',
                     device.modem_writept)
        bb_messenging.log("Saving EP data: " + str(device.interface) + ", " +
                          str(device.readpt) + ", " + str(device.writept) +
                          ", " + str(device.modem_readpt) + ", " +
                          str(device.modem_writept))
        bb_prefs.save_prefs()