func()

in nmxact/nmble/naked_sesn.go [459:518]


func (s *NakedSesn) openOnce() (bool, error) {
	s.mtx.Lock()
	s.state = NS_STATE_OPENING_ACTIVE
	s.mtx.Unlock()

	if err := s.init(); err != nil {
		return false, err
	}

	// Listen for disconnect in the background.
	s.disconnectListen()

	if err := s.conn.Connect(
		s.cfg.Ble.OwnAddrType,
		s.cfg.PeerSpec.Ble,
		s.cfg.Ble.Central.ConnTimeout); err != nil {

		// An ENOTCONN error code implies the "conn_find" request failed
		// because the connection dropped immediately after being established.
		// If this happened, retry the connect procedure.
		bhdErr := nmxutil.ToBleHost(err)
		retry := bhdErr != nil && bhdErr.Status == ERR_CODE_ENOTCONN
		return retry, err
	}

	if err := s.conn.ExchangeMtu(); err != nil {
		// An ENOTCONN error code implies the connection dropped before the
		// first ACL data transmission.  If this happened, retry the connect
		// procedure.
		bhdErr := nmxutil.ToBleHost(err)
		retry := bhdErr != nil && bhdErr.Status == ERR_CODE_ENOTCONN
		return retry, err
	}

	if err := s.conn.DiscoverSvcs(); err != nil {
		return false, err
	}

	if chr, _ := s.getChr(s.mgmtChrs.NmpRspChr); chr != nil {
		if chr.SubscribeType() != 0 {
			if err := s.conn.Subscribe(chr); err != nil {
				return false, err
			}
		}
	}

	// Listen for incoming notifications in the background.
	s.notifyListen()

	// Listen for authentication IO requests in the background.
	s.smIoDemandListen()

	if s.cfg.Ble.EncryptWhen == BLE_ENCRYPT_ALWAYS {
		if err := s.initiateSecurity(); err != nil {
			return false, err
		}
	}

	return false, nil
}