Example #1
0
func newMobileConnectionForDevice(id, uuid string, devPath dbus.ObjectPath, active bool) (cpath dbus.ObjectPath, err error) {
	logger.Infof("new mobile connection, id=%s, uuid=%s, devPath=%s", id, uuid, devPath)

	// guess default plan for mobile device
	countryCode, _ := iso.GetLocaleCountryCode()
	serviceType := getMobileDeviceServicType(devPath)
	plan, err := getDefaultPlanForMobileDevice(countryCode, serviceType)
	if err != nil {
		return
	}

	data := newMobileConnectionData("mobile", uuid, serviceType)
	addSettingSection(data, sectionCache)
	logicSetSettingVkMobileCountry(data, countryCode)
	logicSetSettingVkMobileProvider(data, plan.ProviderName)
	logicSetSettingVkMobilePlan(data, mobileprovider.MarshalPlan(plan))
	refileSectionCache(data)

	if active {
		cpath, _, err = nmAddAndActivateConnection(data, devPath)
	} else {
		cpath, err = nmAddConnection(data)
	}
	return
}
func logicSetSettingVkMobileProvider(data connectionData, provider string) (err error) {
	logger.Info("set", NM_SETTING_VK_MOBILE_PROVIDER, provider)
	setSettingCacheKey(data, NM_SETTING_VK_MOBILE_PROVIDER, provider)
	if provider != mobileProviderValueCustom {
		defaultPlan, err := mobileprovider.GetDefaultPlan(getSettingVkMobileCountry(data), provider)
		if err == nil {
			err = logicSetSettingVkMobilePlan(data, mobileprovider.MarshalPlan(defaultPlan))
		}
	} else {
		syncMoibleConnectionId(data)
	}
	return
}
func generalGetSettingVkeyAvailableValues(data connectionData, section, key string) (values []kvalue) {
	switch section {
	case NM_SETTING_VS_MOBILE:
		switch key {
		case NM_SETTING_VK_MOBILE_COUNTRY:
			codeList, _ := mobileprovider.GetAllCountryCode()
			for _, code := range codeList {
				if name, err := iso.GetCountryNameForCode(code); err == nil {
					values = append(values, kvalue{code, name})
				} else {
					logger.Error(err, code)
				}
			}
			// sort country list
			sortKvalues(values)
		case NM_SETTING_VK_MOBILE_PROVIDER:
			countryCode := getSettingVkMobileCountry(data)
			names, _ := mobileprovider.GetProviderNames(countryCode)
			for _, name := range names {
				values = append(values, kvalue{name, name})
			}
			values = append(values, kvalue{mobileProviderValueCustom, Tr("Custom")})
		case NM_SETTING_VK_MOBILE_PLAN:
			countryCode := getSettingVkMobileCountry(data)
			providerName := getSettingVkMobileProvider(data)
			plans, _ := mobileprovider.GetPlans(countryCode, providerName)
			for _, p := range plans {
				if len(p.Name) > 0 {
					values = append(values, kvalue{mobileprovider.MarshalPlan(p), p.Name})
				} else {
					values = append(values, kvalue{mobileprovider.MarshalPlan(p), Tr("Default")})
				}
			}
		case NM_SETTING_VK_MOBILE_SERVICE_TYPE:
			values = []kvalue{
				kvalue{connectionMobileGsm, Tr("GSM (GPRS, UMTS)")},
				kvalue{connectionMobileCdma, Tr("CDMA (1xRTT, EVDO)")},
			}
		}
	case NM_SETTING_VS_VPN:
		switch key {
		case NM_SETTING_VK_VPN_TYPE:
			values = []kvalue{
				kvalue{connectionVpnL2tp, Tr("L2TP")},
				kvalue{connectionVpnPptp, Tr("PPTP")},
				kvalue{connectionVpnOpenconnect, Tr("OpenConnect")},
				kvalue{connectionVpnOpenvpn, Tr("OpenVPN")},
				kvalue{connectionVpnVpnc, Tr("VPNC")},
			}
		}
	case section8021x:
		switch key {
		case NM_SETTING_VK_802_1X_EAP:
			values = getSetting8021xAvailableValues(data, NM_SETTING_802_1X_EAP)
		}
	case sectionWirelessSecurity:
		switch key {
		case NM_SETTING_VK_WIRELESS_SECURITY_KEY_MGMT:
			if getSettingWirelessMode(data) == NM_SETTING_WIRELESS_MODE_INFRA {
				values = []kvalue{
					kvalue{"none", Tr("None")},
					kvalue{"wep", Tr("WEP 40/128-bit Key")},
					kvalue{"wpa-psk", Tr("WPA/WPA2 Personal")},
					kvalue{"wpa-eap", Tr("WPA/WPA2 Enterprise")},
				}
			} else {
				values = []kvalue{
					kvalue{"none", Tr("None")},
					kvalue{"wep", Tr("WEP 40/128-bit Key")},
					kvalue{"wpa-psk", Tr("WPA/WPA2 Personal")},
				}
			}
		}
	case sectionVpnL2tpPpp:
		switch key {
		case NM_SETTING_VK_VPN_L2TP_MPPE_SECURITY:
			values = []kvalue{
				kvalue{"default", Tr("All Available (default)")},
				kvalue{"128-bit", Tr("128-bit (most secure)")},
				kvalue{"40-bit", Tr("40-bit (less secure)")},
			}
		}
	case sectionVpnPptpPpp:
		switch key {
		case NM_SETTING_VK_VPN_PPTP_MPPE_SECURITY:
			values = []kvalue{
				kvalue{"default", Tr("All Available (default)")},
				kvalue{"128-bit", Tr("128-bit (most secure)")},
				kvalue{"40-bit", Tr("40-bit (less secure)")},
			}
		}
	case sectionVpnVpncAdvanced:
		switch key {
		case NM_SETTING_VK_VPN_VPNC_KEY_ENCRYPTION_METHOD:
			values = []kvalue{
				kvalue{"secure", Tr("Secure (default)")},
				kvalue{"weak", Tr("Weak")},
				kvalue{"none", Tr("None")},
			}
		}
	}

	if len(values) == 0 {
		logger.Warningf("there is no available values for virtual key, %s->%s", section, key)
	}
	return
}