コード例 #1
0
ファイル: manager.go プロジェクト: felixonmars/dde-daemon
func (m *EntryProxyerManager) registerEntry(name string) {
	if !isEntryNameValid(name) {
		return
	}
	logger.Debugf("register entry: %s", name)
	entryId, ok := getEntryId(name)
	if !ok {
		return
	}
	logger.Debugf("register entry id: %s", entryId)
	entry, err := NewEntryProxyer(entryId)
	if err != nil {
		logger.Warningf("register entry failed: %v", err)
		return
	}
	err = dbus.InstallOnSession(entry)
	if err != nil {
		logger.Warningf("register entry failed: %v", err)
		return
	}
	m.Entries = append(m.Entries, entry)

	dbus.Emit(m, "Added", dbus.ObjectPath(entry.GetDBusInfo().ObjectPath))

	logger.Infof("register entry success: %s", name)
}
コード例 #2
0
ファイル: utils_nm.go プロジェクト: felixonmars/dde-daemon
func nmActivateConnection(cpath, devPath dbus.ObjectPath) (apath dbus.ObjectPath, err error) {
	spath := dbus.ObjectPath("/")
	apath, err = nmManager.ActivateConnection(cpath, devPath, spath)
	if err != nil {
		if data, err := nmGetConnectionData(cpath); err == nil {
			nmHandleActivatingError(data, devPath)
		}
		logger.Error(err)
		return
	}
	return
}
コード例 #3
0
func doNewConnectionSession(devPath dbus.ObjectPath, uuid string) (s *ConnectionSession) {
	s = &ConnectionSession{}
	s.sessionPath = dbus.ObjectPath(fmt.Sprintf("/com/deepin/daemon/ConnectionSession/%s", utils.RandString(8)))
	s.devPath = devPath
	s.Uuid = uuid
	s.data = make(connectionData)
	s.AvailableVirtualSections = make([]string, 0)
	s.AvailableKeys = make(map[string][]string)
	s.Errors = make(sessionErrors)
	s.settingKeyErrors = make(sessionErrors)
	return s
}
コード例 #4
0
ファイル: utils_nm.go プロジェクト: felixonmars/dde-daemon
func nmAddAndActivateConnection(data connectionData, devPath dbus.ObjectPath) (cpath, apath dbus.ObjectPath, err error) {
	if len(devPath) == 0 {
		devPath = "/"
	}
	spath := dbus.ObjectPath("/")
	cpath, apath, err = nmManager.AddAndActivateConnection(data, devPath, spath)
	if err != nil {
		nmHandleActivatingError(data, devPath)
		logger.Error(err, "devPath:", devPath)
		return
	}
	return
}
コード例 #5
0
ファイル: utils_nm.go プロジェクト: felixonmars/dde-daemon
func nmGeneralGetDeviveSysPath(devPath dbus.ObjectPath) (sysPath string, err error) {
	dev, err := nmNewDevice(devPath)
	if err != nil {
		return
	}
	switch dev.DeviceType.Get() {
	case NM_DEVICE_TYPE_MODEM:
		sysPath, _ = mmGetModemDeviceSysPath(dbus.ObjectPath(dev.Udi.Get()))
	default:
		sysPath = dev.Udi.Get()
	}
	return
}
コード例 #6
0
ファイル: agent.go プロジェクト: felixonmars/dde-daemon
func (m *Manager) FeedSecret(path string, name, key string, autoConnect bool) {
	logger.Debug("FeedSecret:", path, name, "xxxx")

	opath := dbus.ObjectPath(path)
	m.agent.feedSecret(opath, name, key)

	// FIXME: update secret data in connection settings manually to fix
	// password popup issue when editing such connections
	data, err := nmGetConnectionData(opath)
	if err != nil {
		return
	}
	generalSetSettingAutoconnect(data, autoConnect)
	doFillSecret(data, data, name, key)
	nmUpdateConnectionData(opath, data)
}
コード例 #7
0
ファイル: system_info.go プロジェクト: felixonmars/dde-daemon
func getDiskCap() (uint64, error) {
	udisk, err := udisks2.NewObjectManager(
		"org.freedesktop.UDisks2",
		"/org/freedesktop/UDisks2")
	if err != nil {
		return 0, err
	}

	var (
		diskCap uint64
		driList []dbus.ObjectPath
	)
	managers, _ := udisk.GetManagedObjects()
	for _, value := range managers {
		if _, ok := value["org.freedesktop.UDisks2.Block"]; ok {
			v := value["org.freedesktop.UDisks2.Block"]["Drive"]
			path := v.Value().(dbus.ObjectPath)
			if path != dbus.ObjectPath("/") {
				flag := false
				l := len(driList)
				for i := 0; i < l; i++ {
					if driList[i] == path {
						flag = true
						break
					}
				}
				if !flag {
					driList = append(driList, path)
				}
			}
		}
	}

	for _, driver := range driList {
		_, driExist := managers[driver]
		rm, _ := managers[driver]["org.freedesktop.UDisks2.Drive"]["Removable"]
		if driExist && !(rm.Value().(bool)) {
			size := managers[driver]["org.freedesktop.UDisks2.Drive"]["Size"]
			diskCap += size.Value().(uint64)
		}
	}

	udisks2.DestroyObjectManager(udisk)
	return diskCap, nil
}
コード例 #8
0
ファイル: utils_nm.go プロジェクト: felixonmars/dde-daemon
func nmGeneralGetDeviceIdentifier(devPath dbus.ObjectPath) (devId string, err error) {
	// get device unique identifier, use hardware address if exists
	dev, err := nmNewDevice(devPath)
	if err != nil {
		return
	}
	devType := dev.DeviceType.Get()
	switch devType {
	case NM_DEVICE_TYPE_MODEM:
		modemPath := dev.Udi.Get()
		devId, err = mmGetModemDeviceIdentifier(dbus.ObjectPath(modemPath))
	case NM_DEVICE_TYPE_ADSL:
		err = fmt.Errorf("could not get adsl device identifier now")
		logger.Error(err)
	default:
		devId, err = nmGeneralGetDeviceHwAddr(devPath)
	}
	return
}
コード例 #9
0
ファイル: battery.go プロジェクト: felixonmars/dde-daemon
func (batGroup *batteryGroup) AddBatteryDevice(path dbus.ObjectPath) {
	batGroup.changeLock.Lock()
	defer batGroup.changeLock.Unlock()
	if batGroup.isBatteryPathExist(path) {
		return
	}

	dev, err := libupower.NewDevice(UPOWER_BUS_NAME, dbus.ObjectPath(path))
	if err != nil {
		logger.Warning("New Device Failed:", err)
		return
	}

	if dev.Type.Get() != DeviceTypeBattery {
		return
	}

	batGroup.BatList = append(batGroup.BatList,
		newBatteryDevice(dev, batGroup.propChangedHandler))
}
コード例 #10
0
func NewEntryProxyer(entryId string) (*EntryProxyer, error) {
	if core, err := NewRemoteEntry(entryDestPrefix+entryId, dbus.ObjectPath(entryPathPrefix+entryId)); err != nil {
		return nil, err
	} else {
		remoteEntryId := core.Id.Get()
		if "" == remoteEntryId {
			return nil, errors.New("Empty remote entry id")
		}
		e := &EntryProxyer{
			core:    core,
			entryId: entryId,
			Id:      remoteEntryId,
			Type:    core.Type.Get(),
			Data:    core.Data.Get(),
		}
		e.core.ConnectDataChanged(func(key, value string) {
			if e.Data != nil {
				e.Data[key] = value
				dbus.Emit(e, "DataChanged", key, value)
			}
		})
		return e, nil
	}
}
コード例 #11
0
ファイル: agent.go プロジェクト: felixonmars/dde-daemon
func (m *Manager) CancelSecret(path string, name string) {
	logger.Debug("CancelSecret:", path, name)
	m.agent.CancelGetSecrets(dbus.ObjectPath(path), name)
}
コード例 #12
0
func (m *Manager) doGetActiveConnectionInfo(apath, devPath dbus.ObjectPath) (acinfo activeConnectionInfo, err error) {
	var connType, connName, mobileNetworkType, security, devType, devIfc, hwAddress, speed string
	var ip4Address, ip4Mask string
	var ip4Gateways, ip4Dnses []string
	var ip6Address, ip6Prefix string
	var ip6Gateways, ip6Dnses []string
	var ip4Info ip4ConnectionInfo
	var ip6Info ip6ConnectionInfo

	// active connection
	nmAConn, err := nmNewActiveConnection(apath)
	if err != nil {
		return
	}
	nmConn, err := nmNewSettingsConnection(nmAConn.Connection.Get())
	if err != nil {
		return
	}

	// device
	nmDev, err := nmNewDevice(devPath)
	if err != nil {
		return
	}
	devType = getCustomDeviceType(nmDev.DeviceType.Get())
	devIfc = nmDev.Interface.Get()
	if devType == deviceModem {
		mobileNetworkType = mmGetModemMobileNetworkType(dbus.ObjectPath(nmDev.Udi.Get()))
	}

	// connection data
	hwAddress, err = nmGeneralGetDeviceHwAddr(devPath)
	if err != nil {
		hwAddress = ""
	}
	speed = nmGeneralGetDeviceSpeed(devPath)

	cdata, err := nmConn.GetSettings()
	if err != nil {
		return
	}
	connName = getSettingConnectionId(cdata)
	connType = getCustomConnectionType(cdata)

	// security
	use8021xSecurity := false
	switch getSettingConnectionType(cdata) {
	case NM_SETTING_WIRED_SETTING_NAME:
		if getSettingVk8021xEnable(cdata) {
			use8021xSecurity = true
		} else {
			security = Tr("None")
		}
	case NM_SETTING_WIRELESS_SETTING_NAME:
		switch getSettingVkWirelessSecurityKeyMgmt(cdata) {
		case "none":
			security = Tr("None")
		case "wep":
			security = Tr("WEP 40/128-bit Key")
		case "wpa-psk":
			security = Tr("WPA/WPA2 Personal")
		case "wpa-eap":
			use8021xSecurity = true
		}
	}
	if use8021xSecurity {
		switch getSettingVk8021xEap(cdata) {
		case "tls":
			security = "EAP/" + Tr("TLS")
		case "md5":
			security = "EAP/" + Tr("MD5")
		case "leap":
			security = "EAP/" + Tr("LEAP")
		case "fast":
			security = "EAP/" + Tr("FAST")
		case "ttls":
			security = "EAP/" + Tr("Tunneled TLS")
		case "peap":
			security = "EAP/" + Tr("Protected EAP")
		}
	}

	// ipv4
	if ip4Path := nmDev.Ip4Config.Get(); isNmObjectPathValid(ip4Path) {
		ip4Address, ip4Mask, ip4Gateways, ip4Dnses = nmGetIp4ConfigInfo(ip4Path)
	}
	ip4Info = ip4ConnectionInfo{
		Address:  ip4Address,
		Mask:     ip4Mask,
		Gateways: ip4Gateways,
		Dnses:    ip4Dnses,
	}

	// ipv6
	if ip6Path := nmDev.Ip6Config.Get(); isNmObjectPathValid(ip6Path) {
		ip6Address, ip6Prefix, ip6Gateways, ip6Dnses = nmGetIp6ConfigInfo(ip6Path)
	}
	ip6Info = ip6ConnectionInfo{
		Address:  ip6Address,
		Prefix:   ip6Prefix,
		Gateways: ip6Gateways,
		Dnses:    ip6Dnses,
	}

	acinfo = activeConnectionInfo{
		IsPrimaryConnection: nmGetPrimaryConnection() == apath,
		ConnectionType:      connType,
		ConnectionName:      connName,
		MobileNetworkType:   mobileNetworkType,
		Security:            security,
		DeviceType:          devType,
		DeviceInterface:     devIfc,
		HwAddress:           hwAddress,
		Speed:               speed,
		Ip4:                 ip4Info,
		Ip6:                 ip6Info,
	}
	return
}
コード例 #13
0
func (sh *stateHandler) watch(path dbus.ObjectPath) {
	defer func() {
		if err := recover(); err != nil {
			sh.locker.Lock()
			defer sh.locker.Unlock()
			delete(sh.devices, path)
			logger.Error(err)
		}
	}()
	if dev, err := nmNewDevice(path); err == nil {
		sh.locker.Lock()
		defer sh.locker.Unlock()
		sh.devices[path] = &deviceStateInfo{nmDev: dev}
		sh.devices[path].devType = dev.DeviceType.Get()
		sh.devices[path].devUdi = dev.Udi.Get()
		if data, err := nmGetDeviceActiveConnectionData(path); err == nil {
			// remember active connection id if exists
			sh.devices[path].aconnId = getSettingConnectionId(data)
		}
		// connect signals
		dev.ConnectStateChanged(func(newState, oldState, reason uint32) {
			sh.locker.Lock()
			defer sh.locker.Unlock()
			dsi, ok := sh.devices[path]
			if !ok {
				// the device already been removed
				return
			}

			switch newState {
			case NM_DEVICE_STATE_PREPARE:
				if data, err := nmGetDeviceActiveConnectionData(path); err == nil {
					dsi.aconnId = getSettingConnectionId(data)
				}
			case NM_DEVICE_STATE_ACTIVATED:
				icon := generalGetNotifyConnectedIcon(dsi.devType, path)
				msg := dsi.aconnId
				notify(icon, Tr("Connected"), msg)
			case NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_DISCONNECTED,
				NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_UNAVAILABLE:
				logger.Infof("device disconnected, type %s, %d => %d, reason[%d] %s", getCustomDeviceType(dsi.devType), oldState, newState, reason, deviceErrorTable[reason])

				// ignore device removed signals for that could not
				// query related information correct
				if reason == NM_DEVICE_STATE_REASON_REMOVED {
					return
				}

				// notify only when network enabled and the device activated before
				if !nmGetNetworkEnabled() || !isDeviceStateInActivating(oldState) {
					return
				}

				// fix reasons
				switch dsi.devType {
				case NM_DEVICE_TYPE_ETHERNET:
					if reason == NM_DEVICE_STATE_REASON_CARRIER {
						reason = GUESS_NM_DEVICE_STATE_REASON_CABLE_UNPLUGGED
					}
				case NM_DEVICE_TYPE_MODEM:
					if isDeviceStateReasonInvalid(reason) {
						// mobile device is specially, fix its reasons here
						signalQuality, _ := mmGetModemDeviceSignalQuality(dbus.ObjectPath(dsi.devUdi))
						if signalQuality == 0 {
							reason = GUESS_NM_DEVICE_STATE_REASON_MODEM_NO_SIGNAL
						} else {
							reason = GUESS_NM_DEVICE_STATE_REASON_MODEM_WRONG_PLAN
						}
					}
				}

				// ignore invalid reasons
				if isDeviceStateReasonInvalid(reason) {
					return
				}

				var icon, msg string
				icon = generalGetNotifyDisconnectedIcon(dsi.devType, path)
				if len(msg) == 0 {
					if newState == NM_DEVICE_STATE_DISCONNECTED && reason == NM_DEVICE_STATE_REASON_USER_REQUESTED {
						msg = dsi.aconnId
					} else {
						msg = deviceErrorTable[reason]
					}
				}
				notify(icon, Tr("Disconnected"), msg)
			}
		})
	}
}
コード例 #14
0
func (m *Manager) newDevice(devPath dbus.ObjectPath) (dev *device, err error) {
	nmDev, err := nmNewDevice(devPath)
	if err != nil {
		return
	}

	dev = &device{
		nmDev:     nmDev,
		nmDevType: nmDev.DeviceType.Get(),
		Path:      nmDev.Path,
		State:     nmDev.State.Get(),
	}
	dev.Managed = nmGeneralIsDeviceManaged(devPath)
	dev.Vendor = nmGeneralGetDeviceVendor(devPath)
	dev.UsbDevice = nmGeneralIsUsbDevice(devPath)
	dev.id, _ = nmGeneralGetDeviceIdentifier(devPath)
	dev.udi = dev.nmDev.Udi.Get()
	dev.UniqueUuid = nmGeneralGetDeviceUniqueUuid(devPath)

	// dispatch for different device types
	switch dev.nmDevType {
	case NM_DEVICE_TYPE_ETHERNET:
		if nmDevWired, err := nmNewDeviceWired(dev.Path); err == nil {
			dev.HwAddress = nmDevWired.HwAddress.Get()
		}
		m.ensureWiredConnectionExists(dev.Path, true)
	case NM_DEVICE_TYPE_WIFI:
		if nmDevWireless, err := nmNewDeviceWireless(dev.Path); err == nil {
			dev.HwAddress = nmDevWireless.HwAddress.Get()
			dev.nmDevWireless = nmDevWireless

			// connect property, about wireless active access point
			dev.nmDevWireless.ActiveAccessPoint.ConnectChanged(func() {
				if !m.isDeviceExists(devPath) {
					return
				}
				m.devicesLock.Lock()
				defer m.devicesLock.Unlock()
				dev.ActiveAp = nmDevWireless.ActiveAccessPoint.Get()
				m.setPropDevices()
			})
			dev.ActiveAp = nmDevWireless.ActiveAccessPoint.Get()

			// connect signal AccessPointAdded() and AccessPointRemoved()
			dev.nmDevWireless.ConnectAccessPointAdded(func(apPath dbus.ObjectPath) {
				m.addAccessPoint(dev.Path, apPath)
			})
			dev.nmDevWireless.ConnectAccessPointRemoved(func(apPath dbus.ObjectPath) {
				m.removeAccessPoint(dev.Path, apPath)
			})
			for _, apPath := range nmGetAccessPoints(dev.Path) {
				m.addAccessPoint(dev.Path, apPath)
			}
		}
	case NM_DEVICE_TYPE_MODEM:
		if len(dev.id) == 0 {
			// some times, modem device will not be identified
			// successful for battery issue, so check and ignore it
			// here
			err = fmt.Errorf("modem device is not properly identified, please re-plugin it")
			return
		}
		m.ensureMobileConnectionExists(dev.Path, false)
		go func() {
			// disable autoconnect property for mobile devices
			// notice: sleep is necessary seconds before setting dbus values
			// FIXME: seems network-manager will restore Autoconnect's value some times
			time.Sleep(3 * time.Second)
			nmSetDeviceAutoconnect(dev.Path, false)
		}()
		if mmDevModem, err := mmNewModem(dbus.ObjectPath(dev.udi)); err == nil {
			dev.mmDevModem = mmDevModem

			// connect properties
			dev.mmDevModem.AccessTechnologies.ConnectChanged(func() {
				if !m.isDeviceExists(devPath) {
					return
				}
				m.devicesLock.Lock()
				defer m.devicesLock.Unlock()
				dev.MobileNetworkType = mmDoGetModemMobileNetworkType(mmDevModem.AccessTechnologies.Get())
				m.setPropDevices()
			})
			dev.MobileNetworkType = mmDoGetModemMobileNetworkType(mmDevModem.AccessTechnologies.Get())

			dev.mmDevModem.SignalQuality.ConnectChanged(func() {
				if !m.isDeviceExists(devPath) {
					return
				}
				m.devicesLock.Lock()
				defer m.devicesLock.Unlock()
				dev.MobileSignalQuality = mmDoGetModemDeviceSignalQuality(mmDevModem.SignalQuality.Get())
				m.setPropDevices()
			})
			dev.MobileSignalQuality = mmDoGetModemDeviceSignalQuality(mmDevModem.SignalQuality.Get())
		}
	}

	// connect signal
	dev.nmDev.ConnectStateChanged(func(newState, oldState, reason uint32) {
		logger.Infof("device state changed, %d => %d, reason[%d] %s", oldState, newState, reason, deviceErrorTable[reason])
		if !m.isDeviceExists(devPath) {
			return
		}

		m.devicesLock.Lock()
		defer m.devicesLock.Unlock()
		if reason == NM_DEVICE_STATE_REASON_REMOVED {
			return
		}
		dev.State = newState
		dev.Managed = nmGeneralIsDeviceManaged(dev.Path)
		m.setPropDevices()

		m.config.updateDeviceConfig(dev.Path)
		m.config.syncDeviceState(dev.Path)
	})
	dev.State = dev.nmDev.State.Get()

	m.config.addDeviceConfig(devPath)
	m.switchHandler.initDeviceState(devPath)

	return
}