code: func (n *NetworkServerAPI) GetNextDownlinkFCntForDevEUI(ctx context.Context, req *ns.GetNextDownlinkFCntForDevEUIRequest) (*ns.GetNextDownlinkFCntForDevEUIResponse, error) {
  	var devEUI lorawan.EUI64
  	var resp ns.GetNextDownlinkFCntForDevEUIResponse
  
  	copy(devEUI[:], req.DevEui)
  
  	ds, err := storage.GetDeviceSession(storage.RedisPool(), devEUI)
  	if err != nil {
  		return nil, errToRPCError(err)
  	}
  
  	if ds.GetMACVersion() == lorawan.LoRaWAN1_0 {
  		resp.FCnt = ds.NFCntDown
  	} else {
  		resp.FCnt = ds.AFCntDown
  	}
  
  	items, err := storage.GetDeviceQueueItemsForDevEUI(storage.DB(), devEUI)
  	if err != nil {
  		return nil, errToRPCError(err)
  	}
  	if count := len(items); count != 0 {
  		resp.FCnt = items[count-1].FCnt + 1 // we want the next usable frame-counter
  	}
  
  	return &resp, nil
  }
docs: // GetNextDownlinkFCntForDevEUI returns the next FCnt that must be used.
  // This also takes device-queue items for the given DevEUI into consideration.
  // In case the device is not activated, this will return an error as no
  // device-session exists.