1/* 2 * Copyright (c) 2007 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * readerstate.h 26 * SmartCardServices 27 */ 28 29#ifndef _H_PCSCD_READER_STATE 30#define _H_PCSCD_READER_STATE 31 32#include "wintypes.h" 33#include "pcsclite.h" 34#include "readerfactory.h" 35#include "eventhandler.h" 36#include <MacTypes.h> 37 38#ifdef __cplusplus 39extern "C" 40{ 41#endif 42 43DWORD SharedReaderState_State(READER_STATE *rs); 44DWORD SharedReaderState_Protocol(READER_STATE *rs); 45DWORD SharedReaderState_Sharing(READER_STATE *rs); 46size_t SharedReaderState_CardAtrLength(READER_STATE *rs); 47LONG SharedReaderState_ReaderID(READER_STATE *rs); 48const unsigned char *SharedReaderState_CardAtr(READER_STATE *rs); 49const char *SharedReaderState_ReaderName(READER_STATE *rs); 50int SharedReaderState_ReaderNameIsEqual(READER_STATE *rs, const char *otherName); 51void SharedReaderState_SetState(READER_STATE *rs, DWORD state); 52void SharedReaderState_SetProtocol(READER_STATE *rs, DWORD newprotocol); 53void SharedReaderState_SetCardAtrLength(READER_STATE *rs, size_t len); 54 55#ifdef __cplusplus 56} 57#endif 58 59 60#if defined(__cplusplus) 61 62#include <security_utilities/threading.h> 63 64namespace PCSCD { 65 66// 67// NB: We are using the fact that on our systems, mutexes provide read/write 68// memory barrier as a side effect to avoid having to flush the shared memory 69// region to disk 70// 71 72 73// 74// A PODWrapper for the PCSC ReaderState structure 75// 76class SharedReaderState : public PodWrapper<SharedReaderState, READER_STATE> 77{ 78public: 79 80 LONG xreaderID() const { Atomic<int>::barrier(); return ntohl(readerID); } 81 void xreaderID(LONG rid) { Atomic<int>::barrier(); readerID = htonl(rid); } 82 83 DWORD xreaderState() const { Atomic<int>::barrier(); return ntohl(readerState); } 84 void xreaderState(DWORD state) { Atomic<int>::barrier(); readerState = htonl(state); } 85 86 DWORD sharing() const { Atomic<int>::barrier(); return ntohl(readerSharing); } 87 void sharing(DWORD sharing) { Atomic<int>::barrier(); readerSharing = htonl(sharing); } 88 89 DWORD xlockState() const { Atomic<int>::barrier(); return ntohl(lockState); } 90 void xlockState(DWORD state) { Atomic<int>::barrier(); lockState = htonl(state); } 91 92 DWORD xcardProtocol() const { Atomic<int>::barrier(); return ntohl(cardProtocol); } 93 void xcardProtocol(DWORD prot) { Atomic<int>::barrier(); cardProtocol = htonl(prot); } 94 95 // strings 96 const char *xreaderName() const { Atomic<int>::barrier(); return readerName; } 97 void xreaderName(const char *rname, size_t len = MAX_READERNAME) { Atomic<int>::barrier(); strlcpy(readerName, rname, len); } 98 size_t readerNameLength() const { return strlen(readerName); } 99 void xreaderNameClear() { Atomic<int>::barrier(); memset(readerName, 0, sizeof(readerName)); } 100 101 const unsigned char *xcardAtr() const { Atomic<int>::barrier(); return cardAtr; } 102 unsigned char *xcardAtr() { Atomic<int>::barrier(); return cardAtr; } 103 void xcardAtr(const unsigned char *atr, size_t len) { Atomic<int>::barrier(); 104 memcpy((char *)&cardAtr[0], (const char *)atr, len); cardAtrLength = htonl(len); } 105 size_t xcardAtrLength() const { Atomic<int>::barrier(); return ntohl(cardAtrLength); } 106 void xcardAtrLength(DWORD len) { Atomic<int>::barrier(); cardAtrLength = htonl(len); } 107 void xcardAtrClear() { Atomic<int>::barrier(); memset(cardAtr, 0, sizeof(cardAtr)); } 108}; 109 110 111 112} // end namespace PCSCD 113 114#endif /* __cplusplus__ */ 115 116#endif //_H_PCSCD_READER_STATE 117 118