Monday, August 22, 2005

Compiling Apps with PCSC library in Mac OS X

Reverse engineering things is part of the fun in working with Linux. Irritation and frustation are the work-hazards in these environments. I encountered such a 'fun' situation when trying to compile a PCSC app for smart card reader communication in Mac OS X.

The normal libraries linked with apps for smartcard communication are the pthread and the pcsclite libraries. All is well with pthread library being present in /usr/lib directory. But, I cudnt find the pcsclite library which will normally be available in /usr/local/lib in other linux distributions. I 'grep'ed from root to bottom and got only binary files' links.

There started my reverse-lookup work. After much search, I fell upon the otool command. On running this command with the pre-existing pcsctest tool, i fell upon the following..


/usr/bin/pcsctest:
/System/Library/Frameworks/PCSC.framework/Versions/A/PCSC
(compatibility version 1.0.0, current version 31.0.0)

/usr/lib/libSystem.B.dylib (compatibility version
1.0.0, current version 88.0.0)

Using this as a backbone, I compiled my utility as follows

gcc -o lint pcscutil.c 
-I /System/Library/Frameworks/PCSC.framework/Headers/
-lpthread
-L/System/Library/Frameworks/PCSC.framework/Versions/A/
-framework PCSC

Voila!! it compiled!!!. What was the problem in the first place? All SCard command for the pcsc apps are defined in the pcsclite library. Here in Mac OS, they have been put into the PCSC framework and hence needs to be linked as "-framework" and not as a library. THAT is the secret!!!

PS: I used pcsc daemon version 1.1.2, which comes bundled with the Mac OS X (10.4 darwin).

Thursday, August 11, 2005

Installating Redhat packages - the Debian Way


The RPM (Redhat Package Manager) in Redhat is a very good package manager to install RPMs. One downside to this is the complexities involved with installing big componenets like GCC which involves relationships similar to the way indian government runs.

If you are at the rookie, you tend to get lost.

Debian has the wonderful utility "apt-get" to upgrade their components. An utility to which we just mention the package name, the rest is taken care of by itself. Just one requirement. You need a net connection (Having an OSS and no net connection is like having toothbrush/paste with no teeth). Otherwise, its a damn good utility. The best part is that it takes care of all the dependency issues by ITSELF(!!! if only our government runs like this).

Hey, its open source. So, "apt-get" has jumped the bandwagon of redhat also. The utility is parked here. Just pull out the RPM for your distro and install it with RPM. Check out another blog of mine on how to install a particular RPM here.

Once installed, You should be feeling the power in your hands. The power of APT-GET. Now, to the details.

"/etc/apt/sources.list" is the main configuration file. This file contains the link to the latest RPMs to be retrieved from the freshrpms site. The file should always have an uncommented default suitable to suit your system. I had Fedora. Hence, I added the below lines to support fedora's path

#FC1
rpm http://ayo.freshrpms.net fedora/linux/1/i386 os updates freshrpms


Ok. we are ready to upgrade. First, we need to update the latest packages info from the site. Just call
$ apt-get update
.

This call will take care of collecting the info frmo the site. Now, we are ready to upgrade our system. Let met take the example of me installing libgcc. Check out the sequence of commands I used to install. Let met explain after the commands.

$ apt-cache search libgcc
$ apt-cache showpkg libgcc
$ apt-get install libgcc

The first line is like asking "search the packages list for packages containing the word libgcc and list all for me". I got the following (mine is Fedora). Yours may differ based on how you have updated and your distribution.

$ apt-cache search libgcc
libgcc - GCC version 3.3 shared support library
openoffice.org-libs - OpenOffice.org shared libraries

Now, since we have the package listed, we go to the second line. It talks like "show me the version of the package, what it provides, its dependencies and its reverse-dependencies. Mine listed something like this.

# apt-cache showpkg libgcc
Package: libgcc
Versions:
3.3.2-1(/var/state/apt/lists/ayo.freshrpms.
net_fedora_linux_1_i386_base_pkglist.os)
(/var/lib/rpm/Packages)

Reverse Depends:
glibc,libgcc
glibc,libgcc
glibc,libgcc
glibc,libgcc
gcc,libgcc 3.3.2-1
Dependencies:
3.3.2-1 - /usr/sbin/libgcc_post_upgrade (0 (null))
Provides:
3.3.2-1 - /usr/sbin/libgcc_post_upgrade libgcc_s.so.1
(GLIBC_2.0) libgcc_s.so.1(GCC_3.3.1) libgcc_s.so.1
(GCC_3.3)
libgcc_s.so.1(GCC_3.0) libgcc_s.so.1
Reverse Provides:

Now, we know what are the dependencies this package has, and what are all the related RPMs to be installed. Now, comes the best part. You DONT HAVE TO WORRY about this dependencies stuff. All you need to do is to silently call the third command and see apt-get weave its magic. In the end, all the related upgradation, degradations, installations are done successfully and all will be well that ends well.

Monday, August 08, 2005

Upgrading GCC


Customer requirement made me do the one thing which I had screwed up successfully before.

Upgrade GCC.

I was scared to death to do that. Fortune knocked me in the form of my Scientist friend Vijai. The wise spoke thus:
I dont need to compile from sources. There will be ready-made materials available. Just install those. and Voila it will work

I was happy. So, here goes my knowledge transfer. I know its silly to the core to be happy about making a simple installation work. I am writing this blog to all those kind-hearted newbie homo-sapiens out there who think in my lines.

Status:
1. I am having gcc3.2.2 . I need gcc 3.3.2
2. I am using RHL 9.0 (no fixes/patches/upgrades done so far).

Procedure:
1. First, go to Rpm Finder . Search for "gcc 3.3.2".
2. Downlaod the x86 version of gcc 3.3.2 . It will be listed under Fedora's packages.
I got it from here
3. There are two ways to get it. Either right-click download, or use "wget" command. I used "wget" command.


$ wget ftp://fr2.rpmfind.net/linux/fedora/core/1/
i386/os/Fedora/RPMS/gcc-3.3.2-1.i386.rpm


4. Now, comes the main part. You need to verify if upgrading this package causes any problems in dependencies to you.
$ rpm -ivh --test gcc-3.3.2-1.i386.rpm

To me, it gave three dependency issues. I needed to have later versions of
"libgcc","binutils" and "cpp" packages than those already present.



5. I proceeded to download these packages and did the previous four steps for these.
6. But, upgrading/installing libgcc was creating problems as the older version of this libgcc was needed by gcc3.2.2 (the current version). Hence, I proceeded to uninstall the whole gcc package (cos this was running into loops).


$ rpm -e --nodeps gcc-3.2.2-5 


the "nodeps" options was a request to the "rpm" utility to ignore any dependency issues that may pop-up during the un-installation. I did this because I am going to anyway upgrade the package to the later one. Once this is done, the dependency issues will be solved.


7. So, then, I upgraded all the three packages..
$ rpm -ivh --test <rpm-of-package-to-install> 
- to test for any issues
$ rpm -ivh <rpm-of-package-to-install> 
- to install


8. Finally, I upgraded the latest gcc.
9. Using the "--test" is of paramount importance as this will save u from any embarassment later on. ALWAYS use this before proceeding with the real installation.

10. I am the now happy developer(is it???) with a first-in-my-lifetime successfull upgradation of GCC (of course with the help of our in-house scientist)

Wednesday, August 03, 2005

The Best way to make pcsc lite 1.1.2 work


After about a day of racking my brains to find out a good / decent way to make pcsc lite 1.1.2 to bring back to life, I at last found the best way I can choose right now. I re-installed mac os X. Voila!! I have what I want where I want and how I want. Atleast I expect to find a better way than this before the world ends. You will have to wait a few years(decades or centuries..) to see if that happens.

Tuesday, August 02, 2005

in hell with MAC OS X - pcsc-lite 1.1.2

I was so enthused to upgrade the pcsc framework in my 10.4.1 tiger that i cleaned up the old pcsc daemon, 1.1.2 . Now, the latest is 1.2.9 beta7. all is well till its well. then, somebody wanted support for 1.1.2 cos thats the default one that comes with os x. the really screwed up part is where i am not able to find 1.1.2 package to download / install . god save me. :-(

Monday, August 01, 2005

DFD for Kernel Development

Linux Windows Mac

A log of all that I do and learn in lin,win,mac. hope its useful for u too.