Ejemplo n.º 1
0
func (n *networkServer) getDevAddr(constraints ...string) (types.DevAddr, error) {
	// Generate random DevAddr bytes
	var devAddr types.DevAddr
	copy(devAddr[:], random.Bytes(4))

	// Get a random prefix that matches the constraints
	prefixes := n.GetPrefixesFor(constraints...)
	if len(prefixes) == 0 {
		return types.DevAddr{}, errors.NewErrNotFound(fmt.Sprintf("DevAddr prefix with constraints %v", constraints))
	}

	// Select a prefix
	prefix := prefixes[random.Intn(len(prefixes))]

	// Apply the prefix
	devAddr = devAddr.WithPrefix(prefix)

	return devAddr, nil
}
Ejemplo n.º 2
0
		devID := args[0]
		if !api.ValidID(devID) {
			ctx.Fatalf("Invalid Device ID") // TODO: Add link to wiki explaining device IDs
		}

		appID := util.GetAppID(ctx)

		var nwkSKey types.NwkSKey
		if len(args) > 1 {
			nwkSKey, err = types.ParseNwkSKey(args[1])
			if err != nil {
				ctx.Fatalf("Invalid NwkSKey: %s", err)
			}
		} else {
			ctx.Info("Generating random NwkSKey...")
			copy(nwkSKey[:], random.Bytes(16))
		}

		var appSKey types.AppSKey
		if len(args) > 2 {
			appSKey, err = types.ParseAppSKey(args[2])
			if err != nil {
				ctx.Fatalf("Invalid AppSKey: %s", err)
			}
		} else {
			ctx.Info("Generating random AppSKey...")
			copy(appSKey[:], random.Bytes(16))
		}

		conn, manager := util.GetHandlerManager(ctx, appID)
		defer conn.Close()
Ejemplo n.º 3
0
		if !api.ValidID(devID) {
			ctx.Fatalf("Invalid Device ID") // TODO: Add link to wiki explaining device IDs
		}

		appID := util.GetAppID(ctx)
		appEUI := util.GetAppEUI(ctx)

		var devEUI types.DevEUI
		if len(args) > 1 {
			devEUI, err = types.ParseDevEUI(args[1])
			if err != nil {
				ctx.Fatalf("Invalid DevEUI: %s", err)
			}
		} else {
			ctx.Info("Generating random DevEUI...")
			copy(devEUI[1:], random.Bytes(7))
		}

		var appKey types.AppKey
		if len(args) > 2 {
			appKey, err = types.ParseAppKey(args[2])
			if err != nil {
				ctx.Fatalf("Invalid AppKey: %s", err)
			}
		} else {
			ctx.Info("Generating random AppKey...")
			copy(appKey[:], random.Bytes(16))
		}

		conn, manager := util.GetHandlerManager(ctx, appID)
		defer conn.Close()