def transmit(self, bytes, protocol=None): """Transmit an apdu. Internally calls doTransmit() class method and notify observers upon command/response APDU events. Subclasses must override the doTransmit() class method. @param bytes: list of bytes to transmit @param protocol: the transmission protocol, from CardConnection.T0_protocol, CardConnection.T1_protocol, or CardConnection.RAW_protocol """ Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent( 'command', [bytes, protocol])) data, sw1, sw2 = self.doTransmit(bytes, protocol) Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent( 'response', [data, sw1, sw2])) if self.errorcheckingchain is not None: self.errorcheckingchain[0](data, sw1, sw2) return data, sw1, sw2
def control(self, controlCode, bytes=[]): """Send a control command and buffer. Internally calls doControl() class method and notify observers upon command/response events. Subclasses must override the doControl() class method. controlCode: command code bytes: list of bytes to transmit """ Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('command', [controlCode, bytes])) data = self.doControl(controlCode, bytes) Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('response', data)) if None != self.errorcheckingchain: self.errorcheckingchain[0](data) return data
def connect(self, protocol=None, mode=None, disposition=None): """Connect to card. protocol: a bit mask of the protocols to use, from CardConnection.T0_protocol, CardConnection.T1_protocol, CardConnection.RAW_protocol, CardConnection.T15_protocol mode: passed as-is to the PC/SC layer """ Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('connect'))
def getAttrib(self, attribId): """return the requested attribute @param attribId: attribute id like SCARD_ATTR_VENDOR_NAME """ Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('attrib', [attribId])) data = self.doGetAttrib(attribId) if None != self.errorcheckingchain: self.errorcheckingchain[0](data) return data
def reconnect(self, protocol=None, mode=None, disposition=None): """Reconnect to card. @param protocol: a bit mask of the protocols to use, from L{CardConnection.T0_protocol}, L{CardConnection.T1_protocol}, L{CardConnection.RAW_protocol}, L{CardConnection.T15_protocol} @param mode: SCARD_SHARE_SHARED (default), SCARD_SHARE_EXCLUSIVE or SCARD_SHARE_DIRECT @param disposition: SCARD_LEAVE_CARD, SCARD_RESET_CARD (default), SCARD_UNPOWER_CARD or SCARD_EJECT_CARD """ Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('reconnect'))
def disconnect(self): """Disconnect from card.""" Observable.setChanged(self) Observable.notifyObservers(self, CardConnectionEvent('disconnect'))