def confirmation(self, apdu):
        """This function is called when the application has provided a response
        and needs it to be sent to the client."""
        if _debug: ServerSSM._debug("confirmation %r", apdu)

        # check to see we are in the correct state
        if self.state != AWAIT_RESPONSE:
            if _debug: ServerSSM._debug("    - warning: not expecting a response")

        # abort response
        if (apdu.apduType == AbortPDU.pduType):
            if _debug: ServerSSM._debug("    - abort")

            self.set_state(ABORTED)

            # send the response to the device
            self.response(apdu)
            return

        # simple response
        if (apdu.apduType == SimpleAckPDU.pduType) or (apdu.apduType == ErrorPDU.pduType) or (apdu.apduType == RejectPDU.pduType):
            if _debug: ServerSSM._debug("    - simple ack, error, or reject")

            # transaction completed
            self.set_state(COMPLETED)

            # send the response to the device
            self.response(apdu)
            return

        # complex ack
        if (apdu.apduType == ComplexAckPDU.pduType):
            if _debug: ServerSSM._debug("    - complex ack")

            # save the response and set the segmentation context
            self.set_segmentation_context(apdu)

            # the segment size is the minimum of the size of the largest packet
            # that can be delivered to the client and the largest it can accept
            if (not self.device_info) or (self.device_info.maxNpduLength is None):
                self.segmentSize = self.maxApduLengthAccepted
            else:
                self.segmentSize = min(self.device_info.maxNpduLength, self.maxApduLengthAccepted)
            if _debug: ServerSSM._debug("    - segment size: %r", self.segmentSize)

            # compute the segment count
            if not apdu.pduData:
                # always at least one segment
                self.segmentCount = 1
            else:
                # split into chunks, maybe need one more
                self.segmentCount, more = divmod(len(apdu.pduData), self.segmentSize)
                if more:
                    self.segmentCount += 1
            if _debug: ServerSSM._debug("    - segment count: %r", self.segmentCount)

            # make sure we support segmented transmit if we need to
            if self.segmentCount > 1:
                if _debug: ServerSSM._debug("    - segmentation required, %d segments", self.segmentCount)

                # make sure we support segmented transmit
                if self.segmentationSupported not in ('segmentedTransmit', 'segmentedBoth'):
                    if _debug: ServerSSM._debug("    - server can't send segmented responses")
                    abort = self.abort(AbortReason.segmentationNotSupported)
                    self.response(abort)
                    return

                # make sure client supports segmented receive
                if not self.segmented_response_accepted:
                    if _debug: ServerSSM._debug("    - client can't receive segmented responses")
                    abort = self.abort(AbortReason.segmentationNotSupported)
                    self.response(abort)
                    return

                # make sure we dont exceed the number of segments in our response
                # that the client said it was willing to accept in the request
                if (self.maxSegmentsAccepted is not None) and (self.segmentCount > self.maxSegmentsAccepted):
                    if _debug: ServerSSM._debug("    - client can't receive enough segments")
                    abort = self.abort(AbortReason.apduTooLong)
                    self.response(abort)
                    return

            # initialize the state
            self.segmentRetryCount = 0
            self.initialSequenceNumber = 0
            self.actualWindowSize = None

            # send out the first segment (or the whole thing)
            if self.segmentCount == 1:
                self.response(apdu)
                self.set_state(COMPLETED)
            else:
                self.response(self.get_segment(0))
                self.set_state(SEGMENTED_RESPONSE, self.segmentTimeout)

        else:
            raise RuntimeError("invalid APDU (4)")
def confirmation ( self , apdu ) : if _debug : ServerSSM . _debug ( "confirmation %r" , apdu ) if self . state != AWAIT_RESPONSE : if _debug : ServerSSM . _debug ( "    - warning: not expecting a response" ) if ( apdu . apduType == AbortPDU . pduType ) : if _debug : ServerSSM . _debug ( "    - abort" ) self . set_state ( ABORTED ) self . response ( apdu ) return if ( apdu . apduType == SimpleAckPDU . pduType ) or ( apdu . apduType == ErrorPDU . pduType ) or ( apdu . apduType == RejectPDU . pduType ) : if _debug : ServerSSM . _debug ( "    - simple ack, error, or reject" ) self . set_state ( COMPLETED ) self . response ( apdu ) return if ( apdu . apduType == ComplexAckPDU . pduType ) : if _debug : ServerSSM . _debug ( "    - complex ack" ) self . set_segmentation_context ( apdu ) if ( not self . device_info ) or ( self . device_info . maxNpduLength is None ) : self . segmentSize = self . maxApduLengthAccepted else : self . segmentSize = min ( self . device_info . maxNpduLength , self . maxApduLengthAccepted ) if _debug : ServerSSM . _debug ( "    - segment size: %r" , self . segmentSize ) if not apdu . pduData : self . segmentCount = 1 else : self . segmentCount , more = divmod ( len ( apdu . pduData ) , self . segmentSize ) if more : self . segmentCount += 1 if _debug : ServerSSM . _debug ( "    - segment count: %r" , self . segmentCount ) if self . segmentCount > 1 : if _debug : ServerSSM . _debug ( "    - segmentation required, %d segments" , self . segmentCount ) if self . segmentationSupported not in ( 'segmentedTransmit' , 'segmentedBoth' ) : if _debug : ServerSSM . _debug ( "    - server can't send segmented responses" ) abort = self . abort ( AbortReason . segmentationNotSupported ) self . response ( abort ) return if not self . segmented_response_accepted : if _debug : ServerSSM . _debug ( "    - client can't receive segmented responses" ) abort = self . abort ( AbortReason . segmentationNotSupported ) self . response ( abort ) return if ( self . maxSegmentsAccepted is not None ) and ( self . segmentCount > self . maxSegmentsAccepted ) : if _debug : ServerSSM . _debug ( "    - client can't receive enough segments" ) abort = self . abort ( AbortReason . apduTooLong ) self . response ( abort ) return self . segmentRetryCount = 0 self . initialSequenceNumber = 0 self . actualWindowSize = None if self . segmentCount == 1 : self . response ( apdu ) self . set_state ( COMPLETED ) else : self . response ( self . get_segment ( 0 ) ) self . set_state ( SEGMENTED_RESPONSE , self . segmentTimeout ) else : raise RuntimeError ( "invalid APDU (4)" )
This function is called when the application has provided a response
        and needs it to be sent to the client.